Tricks to manage the available memory in an R session

前端 未结 27 1965
情深已故
情深已故 2020-11-22 01:23

What tricks do people use to manage the available memory of an interactive R session? I use the functions below [based on postings by Petr Pikal and David Hinds to the r-he

27条回答
  •  一个人的身影
    2020-11-22 02:02

    You also can get some benefit using knitr and puting your script in Rmd chuncks.

    I usually divide the code in different chunks and select which one will save a checkpoint to cache or to a RDS file, and

    Over there you can set a chunk to be saved to "cache", or you can decide to run or not a particular chunk. In this way, in a first run you can process only "part 1", another execution you can select only "part 2", etc.

    Example:

    part1
    ```{r corpus, warning=FALSE, cache=TRUE, message=FALSE, eval=TRUE}
    corpusTw <- corpus(twitter)  # build the corpus
    ```
    part2
    ```{r trigrams, warning=FALSE, cache=TRUE, message=FALSE, eval=FALSE}
    dfmTw <- dfm(corpusTw, verbose=TRUE, removeTwitter=TRUE, ngrams=3)
    ```
    

    As a side effect, this also could save you some headaches in terms of reproducibility :)

提交回复
热议问题