【问题标题】:R is not referencing source files correctlyR 没有正确引用源文件
【发布时间】: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


【解决方案1】:

刚找到。

我提到的其中一个文件中有一个循环引用。 static_data 文件引用“functionsfile, but the reference to thefunctions”文件中的数据不正确

更正了这个参考,并解决了问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-10
    • 2013-12-31
    相关资源
    最近更新 更多