r - Get variables that have been created inside a function -
i have created function (which quite long) have saved in .txt file. works (i use source(< >) access it). problem have created few variables in function ie:
myfun<-function(a,b) { var1=.... var2=var1 + .. } now want variables. when include return() inside function, fine: value comes on screen, when type var1 outside function, have error message "the object cannot found". new r, thinking might because "myfun" operates in different envrionment global one, when did
environment() environment: r_globalenv> environment(myfun1) environment: r_globalenv> it seems me problem elsewhere...
any idea?
thanks
if want in nice way, write class , provide print method. within class possible return variables invisible. nice book covers such topics "the art of r programming".
an easy fix save each variable need later on list , return list (as peter pointed out):
return(list(var1=var1, .....))
Comments
Post a Comment