[R] Question on assignment

Christofer Bogaso bogaso.christofer at gmail.com
Sat Mar 16 14:27:24 CET 2013


Hello again, I was trying to understand how I can assign variables in
some other Environments which is different from that variable's
original Environment. Let say I have following nested functions:


fn <- function(x) {
		x1 <- function(y = x) {
				y1 <- log(y)
				y2 <- y^2
				return(0)
			}
		### I want the variable 'y1' is available here. WITHOUT using the
return() within x1()
		return(class(try(x1(), silent = TRUE)))
	}
fn(5)
fn("sd")


Here I want that the variable 'y1' which is defined within the
function x1() should be available in it's parent function fn() but not
in the Global Env. I have tried with the '<<-' operator, however could
not achieve what I want.

Can somebody point me towards the right direction?

Thanks for your help.



More information about the R-help mailing list