Re: [R] Deparse substitute assign with list elements

2015-05-15 Thread William Dunlap
txt <- paste( nm, '<-', tmp, sep='' ) eval( parse(text=txt), parent.frame() ) in `foo()` will do the trick. Yuck. If you use that sort of syntax your code becomes hard to understand and you risk changing variables that users do not want changed. When the use uses somethi

Re: [R] Deparse substitute assign with list elements

2015-05-15 Thread soeren . vogel
Thanks, Bill, I should have googled more carefully: http://stackoverflow.com/questions/9561053/assign-values-to-a-list-element-in-r So, remove assign(nm, tmp, parent.frame()) and add txt <- paste( nm, '<-', tmp, sep='' ) eval( parse(text=txt), parent.frame() ) in `foo(

Re: [R] Deparse substitute assign with list elements

2015-05-14 Thread William Dunlap
You could use a 'replacement function' named 'bar<-', whose last argument is called 'value', and use bar(variable) <- newValue where you currently use foo(variable, newValue). bar <- function(x) { x + 3 } `bar<-` <- function(x, value) { bar(value) } a <- NA bar(a) <- 4 a # [1] 7 b <- list

[R] Deparse substitute assign with list elements

2015-05-14 Thread soeren . vogel
Hello, When I use function `foo` with list elements (example 2), it defines a new object named `b[[1]]`, which is not what I want. How can I change the function code to show the desired behaviour for all data structures passed to the function? Or is there a more appropriate way to sort of "pa