Skip to content
Prev 360812 / 398506 Next

Ensure parameter is a string when passed within an lapply & called function runs a 'substitute' on it

Well, here's a very bad way of doing this:

vars <- names(dataSet)

lapply(vars, function(var) {
  assign("y",var,pos=parent.frame(2))
  testFunc(x = model, pred.data = dataSet,
x.var=eval(y,parent.frame(2)), plot = F)
} )

## results in

[1] "X1"
[1] "X2"
[1] "X3"
[1] "X4"
[1] "X5"
[1] "X6"
[[1]]
[1] "X1"

[[2]]
[1] "X2"

[[3]]
[1] "X3"

[[4]]
[1] "X4"

[[5]]
[1] "X5"

[[6]]
[1] "X6"


Assigning to the calling environment is a bad idea, but I have not
figured out a better way to go about this.


Cheers,
Bert
Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Mon, May 9, 2016 at 2:39 PM, Andrew Clancy <nite at achren.org> wrote: