@@ -313,55 +313,14 @@ formatError <- function(threadNumber, error, args) {
313313# ' Get the total amount of physical memory
314314# '
315315# ' @returns
316- # ' The number of GB of RAM. Returns NA if the function failed. One GB is
317- # ' 1,000,000,000 bytes.
316+ # ' The number of GB of RAM. One GB is 1,000,000,000 bytes.
318317# '
319318# ' @examples
320319# ' getPhysicalMemory()
321320# '
322321# ' @export
323322getPhysicalMemory <- function () {
324- os <- Sys.info()[[' sysname' ]]
325- if (os == " Windows" ) {
326- output <- tryCatch(
327- system(" wmic ComputerSystem get TotalPhysicalMemory /value" , intern = TRUE ),
328- error = function (e ) {
329- return (" " )
330- }
331- )
332- idx <- grep(" TotalPhysicalMemory=" , output , value = TRUE )
333- if (length(idx ) > 0 ) {
334- memoryString <- gsub(" TotalPhysicalMemory=" , " " , idx [1 ])
335- memory <- as.numeric(memoryString )
336- return (memory / (1e9 )) # Convert to GB
337- } else {
338- return (NA )
339- }
340- } else if (os == " Linux" || os == " Darwin" ) {
341- memory <- tryCatch(
342- as.numeric(system(" /usr/sbin/sysctl -n hw.memsize" , intern = TRUE ))/ 1e+09 , # Convert to GB
343- error = function (e ) {
344- return (NA )
345- },
346- warning = function (e ) {
347- return (NA )
348- }
349- )
350- if (! is.na(memory )) {
351- return (memory )
352- } else {
353- memory <- tryCatch({
354- output <- system(" grep MemTotal /proc/meminfo" , intern = TRUE )
355- output <- gsub(" kB" , " " , gsub(" MemTotal:" , " " , output ), ignore.case = TRUE )
356- as.numeric(output ) / 1e6 # Convert to GB
357- },
358- error = function (e ) {
359- return (NA )
360- })
361- return (memory )
362- }
363- } else {
364- warning(" Operating system not supported." )
365- return (NA )
366- }
323+ memory <- memuse :: Sys.meminfo()$ totalram
324+ memory <- memuse :: swap.unit(x , " GB" )
325+ return (memory @ size )
367326}
0 commit comments