【发布时间】:2023-01-26 23:16:23
【问题描述】:
我有一组 R 文件,我想在我的主程序中获取这些文件,并且正在使用 source() 函数。这 5 个文件都在同一个名为 reference_r_scripts 的子目录中
source('reference_r_scripts/libraries.R')
source('reference_r_scripts/environment_variables.R')
source('reference_r_scripts/plot_variables.R')
source('reference_r_scripts/static_data.R')
source('reference_r_scripts/functions.R')
前 3 个源成功,但找不到第 4 个和第 5 个,这很奇怪,因为它们都在同一个文件夹中:
> source('reference_r_scripts/static_data.R')
Error in file(filename, "r", encoding = encoding) :
cannot open the connection
In addition: Warning message:
In file(filename, "r", encoding = encoding) :
cannot open file 'functions.R': No such file or directory
> source('reference_r_scripts/functions.R')
Error in file(filename, "r", encoding = encoding) :
cannot open the connection
In addition: Warning message:
In file(filename, "r", encoding = encoding) :
cannot open file 'plot_variables.R': No such file or directory
只是为了确保它们实际上都存在,list.files() 产生了正确的结果:
> list.files('reference_r_scripts')
[1] "environment_variables.R" "functions.R" "libraries.R" "plot_variables.R"
[5] "static_data.R"
有什么建议可以克服这个问题吗?
【问题讨论】:
-
当您输入
source()全名/文件路径时会发生什么?
标签: r