Alternative to R's `memory.size()` in linux?

前端 未结 3 846
无人及你
无人及你 2020-12-11 15:37

R\'s memory.size() is a Windows only. For other functions (such as windows()) the help page gives pointer to non-windows counterparts.

3条回答
  •  醉梦人生
    2020-12-11 15:58

    Using pryr library:

    library("pryr")
    
    mem_used()
    # 27.9 MB
    
    x <- mem_used()
    x
    # 27.9 MB
    class(x)
    # [1] "bytes"
    

    Result is the same as @RHertel's answer, with pryr we can assign the result into a variable.

    system('grep MemTotal /proc/meminfo')
    # MemTotal:       263844272 kB
    

    To assign to a variable with system call, use intern = TRUE:

    x <- system('grep MemTotal /proc/meminfo', intern = TRUE)
    x
    # [1] "MemTotal:       263844272 kB"
    class(x)
    # [1] "character"
    

提交回复
热议问题