我解释了我的问题:我有两个R脚本。我在第一个脚本中创建了一个变量,希望在第二个脚本中调用该变量。问题是要将此变量放入第一个脚本,我需要编写一些R行,但是我不想将这些行重写到第二个脚本中。
有帮助吗?
编辑:从上一主题开始,我在第二个R脚本中尝试了以下几行:
loadRData <- function(fileName) {
#loads an RData file, and returns it
load(fileName)
print(ls())
n <- readline(prompt="combs") #combs is the name of my variable
get(ls()[as.matrix(n)])
}
select_var <- loadRData('RHO_COR.R') #RHO_COR.R is the name of my first script , I execute this command in my second script
但是我收到警告消息:
Error in load(fileName) :
bad restore file magic number (file may be corrupted) -- no data loaded
In addition: Warning message:
file ‘RHO_COR.R’ has magic number 'libra'
Use of save versions prior to 2 is deprecated