Alex Alex - 3 months ago 22
R Question

r function alias memory space

Does alias function double memory space occupied by the function definition?
Is this alternative aliasing memory saver?

> ss=subset
> ss(glmC, donchian==don & in_fundo==F & C_V=='C', epsilon2)
epsilon2
1 1e-07
> ss
function (x, ...)
UseMethod("subset")
<bytecode: 0x0000000018797e70>
<environment: namespace:base>

# alternative aliasing
> ss=function(...) subset(...)
> ss
function(...) subset(...)
> ss(glmC, donchian==don & in_fundo==F & C_V=='C', epsilon2)
epsilon2
1 1e-07

Answer

Is this alternative aliasing memory saver?

No, it is not.

ss = subset
ss1 = function(...) subset(...)

object.size(ss)
# 832 bytes
object.size(ss1)
# 1280 bytes

We can also using pryr::object_size, which may be more accurate.

library(pryr)
object_size(ss)
# 832 B
object_size(ss1)
# 1.62 kB

However, the differences are so small that it is extremely difficult to imagine a situation in which they would matter. And, if you were in such a memory-tight situation, presumably the most memory-efficient solution would be to not alias at all.