Where does ecdf save its object? (and how to measure it?)

I can't figure out where R is saving data for ecdf . Here are some examples to illustrate this:

 > set.seed(2016-10-30) > x <- rnorm(1e4) > y <- ecdf(x) > object.size(x) 80040 bytes > object.size(y) 3896 bytes > rm(x) > gc() used (Mb) gc trigger (Mb) max used (Mb) Ncells 602079 32.2 1168576 62.5 750400 40.1 Vcells 1183188 9.1 299644732 2286.2 750532746 5726.2 > object.size(y) 3896 bytes > plot(y) # still works... > 

If the size of y is small, it means that the data is stored somewhere. Obviously, it is not stored in x (since I deleted it).

  • It may be in some kind of environment, but how can we access it? So where is this data stored and how can it be obtained?
  • How will this affect memory.limit ()? (i.e., caching or memory limits for executing R processes)
+6
source share
2 answers

The @hadley Advanced R app has a fantastic explanation for closing functions that surround, execute, and invoke environments.

In your specific example, as noted in the comments, the size of the object along with its environment is much larger:

 pryr::compare_size(y) 

You can see the objects that this entails, and their relative sizes with this:

 sapply(codetools::findGlobals(y), function(x) object.size(get(x, environment(y)))) 

You can summarize the last vector to see that this is really what pryr::object_size (164 kB on my machine).

+5
source

You correctly know that the information (and size) is in the y environment:

  ls( envir = environment(y)) #[1] "f" "method" "nobs" "x" "y" "yleft" "yright" str( environment(y)$x ) 3 num [1:10000] -4.01 -3.41 -3.39 -3.38 -3.34 ... str( environment(y)$y ) # num [1:10000] 1e-04 2e-04 3e-04 4e-04 5e-04 6e-04 7e-04 8e-04 9e-04 1e-03 ... 

You access the contents of the environment using ls() . Its use by default on the console has the envir parameter assigned by globalenv() , as this indicates pos = -1L . You can access the values ​​using $ as shown above. Some other functions that may be helpful in understanding this data storage strategy are stepfun and many of the spline functions.

+3
source

Source: https://habr.com/ru/post/1011858/


All Articles