Hi, I often work with R by writing long(ish) Excel-VBA macros
interspersed with calls to R via RExcel. A typical example of this would
be:

Sub VBAMacro()
        'fetch some data from an excel sheet
        'do some basic stuff on said data
        'transfer data from vba to R
        'run some R statements
        'get data back to vba
        'show results on the excel sheet
        'clean R by deleting all vars that were created: rrun
"rm(a,b,c,....)"
end sub

This has two obvious disadvantages, as I have to make sure:
1) not to use R variable names which may already exist
2) to remove all variables (garbage collection)

In order to overcome these issues I was wondering if I should execute
all R statements inside the R macro in a separate namespace. I have
looked at new.env() but am not really sure how it is supposed to be
used. If I type "temp<-new.env()", how do I make sure that all variables
declared from then on end up in the "temp" environment? Once I am done,
is "rm(temp)" sufficient to get rid of all its content?

Basically, I would like to replace the above example with:
Sub VBAMacro()
        rrun "A<-new.env()"
        'fetch some data from an excel sheet
        'do some basic stuff on said data
        'transfer data from vba to R
        'run some R statements
        'get data back to vba
        'show results on the excel sheet
        rrun "rm(A)"
end sub

Thanks
Christian Prinoth

DISCLAIMER:\ L'utilizzo non autorizzato del presente mes...{{dropped:16}}

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to