0

Is there anyway I can store the results of one variable in one R script, and make them available to another R script?

I have this basic script in one file:

B5b=fit(y~.,d_treino_both,model="randomforest",task="class")
P5b=predict(B5b,d_teste)
x=d_teste$y
m5b=mmetric(x,P5b,metric=c("ACC","ACCLASS","CONF", "ROC"))
mgraph(x,P5b,graph= "ROC", baseline=TRUE)
print(m5b)
P5b

Then, I want to make the resuts of P5b variable available to another script. Any help?

rurjais
  • 1
  • 1
  • **From review queue:** Welcome to StackOverflow - please read [How to make a great R reproducible example?](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610) and edit your question afterwards. – help-info.de May 28 '17 at 10:50

2 Answers2

2

Not sure if this is what you are looking for. I think one way you can do that is to source the script1 in script2. I would do something like this and remove any additional variables using rm.

source("script1.R")
Jaap
  • 81,064
  • 34
  • 182
  • 193
S2850951
  • 182
  • 8
0

Perhaps you could try something with dput and the clipboard. Basically, this is just copying the dput of an object to the clipboard and then evaluating the clipboard in the second script. Note that you cannot use the clipboard in the meantime.

# first script
obj <- capture.output(dput(matrix(1:100, 10, 10)))
writeClipboard(str = obj)

# second script
obj2 <- eval(parse(text = readClipboard()))
Vandenman
  • 3,046
  • 20
  • 33