I cannot reference functions/data.frames/variables that I create on the R side using R.
notation inside F#. How is this achieved?
For example, in the below code, I would like to be able to reference symbols
and f1
via intellisense.
open RProvider
open RDotNet
R.eval(R.parse(text="
require(datasets);
volcanoList <- unlist(as.list(volcano));
volcanoMean <- mean(volcanoList);
symbols <- c('volcano', 'volcanoList', 'volcanoMean');
f1 <- function(y) y+1
dfs <- data.frame(a = symbols)
"))
R.eval(R.parse(text="symbols"))
R.symbols // doesn't work
R.f1 // doesn't work
R.dfs // doesn't work
The R type provider does not currently scan the user-created variables in the environment (one problem with this is that they do not really exist until you run the code, so you would see errors in the file if you just opened it).
The closest you can get to something like this is probably using the RData type . This lets you read RData files in a statically typed way. So, if you call save
at the end of your R code:
R.eval(R.parse(text="""
require(datasets);
volcanoList <- unlist(as.list(volcano));
volcanoMean <- mean(volcanoList);
symbols <- c('volcano', 'volcanoList', 'volcanoMean');
save(list=symbols, file="C:/temp/image.rdata")
"""))
You can then read the saved file with nice auto-complete support (I'm not sure if you need to explicitly specify the list of symbols when saving the file, or if you can just save the whole environment):
let data = new RData<"C:/temp/image.rdata">()
data.volcano
data.volcanoList
data.volcanoMean
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.