In Windows only one can do memory.size()
to get the total amount of memory eaten up by the (objects in the) current R
session.
It's also possible to understand the size of an individual object with print( object.size( thing ), units='auto')
which says how many megabytes/kilobytes that particular data-frame/table takes up.
But how to do the equivalent of print( object.size( ---workspace--- ))
?
Looping for (thing in ls()) print( object.size( thing ), units='auto' )
prints the wrong output, such as:
64 bytes
72 bytes
88 bytes
88 bytes
64 bytes
64 bytes
64 bytes
64 bytes
64 bytes
64 bytes
64 bytes
64 bytes
64 bytes
64 bytes
72 bytes
88 bytes
64 bytes
64 bytes
64 bytes
64 bytes
64 bytes
64 bytes
64 bytes
64 bytes
64 bytes
64 bytes
64 bytes
which is not what I meant.
To find the object size in R, we can use object. size function. For example, if we have a data frame called df then the size of df can be found by using the command object. size(df).
The ls() code lists all of the objects in your workspace. The rm() code removes objects in your workspace. You can begin your code with the rm() function to clear all of the objects from your workspace to start with a clean environment.
ls() function in R Language is used to list the names of all the objects that are present in the working directory.
To access file click File and then load workspace. A dialog box will appear, browse to the folder where you saved the . RData file and click open.
To print the size of the whole workspace, you could try the following function:
workspace.size <- function() {
ws <- sum(sapply(ls(envir=globalenv()), function(x)object.size(get(x))))
class(ws) <- "object_size"
ws
}
workspace.size()
# 35192 bytes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With