gpt4 book ai didi

r - 文件错误(文件名, "r",编码=编码): cannot open the connection

转载 作者:行者123 更新时间:2023-12-04 12:23:05 27 4
gpt4 key购买 nike

我有一个 RScript文件(我们称之为 main.r ),它引用了另一个文件,使用以下代码:

source("functions.R")
但是,当我运行 RScript 文件时,它提示以下错误:
    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
我确定,我的 main.R文件在 functions.R 旁边在同一个目录中。
我可以拨打 functions.RRmd ( RMarkdown ) 文件存在于同一目录中

最佳答案

在您的情况下,请尝试添加 setwd("path/to/project/")main.R哪里path/to/project/包含 main.R .

那么你可以source functions.R要么直接通过 source("functions.R")如果两个文件位于同一目录或 source("sub-folder/functions.R")如果后一个文件包含在子文件夹中。

如果您不使用 RStudio项目,可能是 main.R 的工作目录可能是您的主目录。

关于r - 文件错误(文件名, "r",编码=编码): cannot open the connection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54421354/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com