search for: inspired2apathy

Displaying 3 results from an estimated 3 matches for "inspired2apathy".

2011 Mar 17
2
Scope and apply-type functions
So, I've been confused by this for a while. If I want to create functions in an apply, it only uses the desired value for the variable if I create a new local variable: > lapply(1:5,function(h){k=h;function(){k}})[[1]]() [1] 1 > lapply(1:5,function(k){function(){k}})[[1]]() [1] 5 > Normally, a function will use values for a variable if the variable is local to the definition of
2012 Nov 07
4
save/load and package namespaces
Could someone explain to me what namespaces are loaded/saved when objects are saved? Specifically, I'm using this: save(list = ls(all.names = TRUE, envir = envir), file = name, envir = envir) to save out everything from an environment. Later, loading it on another machine, I'm surprised to see the load failing for being unable to load certain packages. Could anyone help me understand
2012 Nov 13
2
Is function(x){x}(5) a valid expression?
I was surprised to notice that statements like: h = function(...){list(...)}(x=4) do not throw syntax errors. R claims that 'h' is now a function, but I can't seem to call it. > h = function(x){list(x)}(4) > is(h) [1] "function" "OptionalFunction" "PossibleMethod" > h() Error in list(x) : 'x' is missing > h(4) Error in h(4)