Tricks to manage the available memory in an R session

前端 未结 27 1971
情深已故
情深已故 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 01:54

    I try to keep the amount of objects small when working in a larger project with a lot of intermediate steps. So instead of creating many unique objects called

    dataframe-> step1 -> step2 -> step3 -> result

    raster-> multipliedRast -> meanRastF -> sqrtRast -> resultRast

    I work with temporary objects that I call temp.

    dataframe -> temp -> temp -> temp -> result

    Which leaves me with less intermediate files and more overview.

    raster  <- raster('file.tif')
    temp <- raster * 10
    temp <- mean(temp)
    resultRast <- sqrt(temp)
    

    To save more memory I can simply remove temp when no longer needed.

    rm(temp)
    

    If I need several intermediate files, I use temp1, temp2, temp3.

    For testing I use test, test2, ...

提交回复
热议问题