在macOS 11.2.1上从RStudio运行R
当从R调用cargo时,例如在使用rextendr包或尝试安装helloextendr时,我分别收到错误sh: cargo: command not found和make: cargo: command not found。但是,从终端调用cargo的工作方式与预期相同。
人们可以从下面看到不同之处。
在R中未找到货物:
> Sys.which("cargo")
# cargo
# ""从航站楼发现货物
% which cargo
$HOME/.cargo/bin/cargo发布于 2021-02-19 11:17:31
原因与这个问题有关:简单地说,macOS有一个不同的$PATH变量,这取决于您是直接使用终端还是使用从dock启动的应用程序(就像R和RStudio一样)。
一种解决方案是使用.Rprofile文件。将以下行添加到主目录或项目主目录中的.Rprofile中。(有关.Rprofile文件的详细信息,请参阅here。)
# R can't find Rust's cargo binary
# issue is because $PATH is different for shell vs. dock launched applications in MacOS
# See: https://stackoverflow.com/questions/48084679/why-do-which-and-sys-which-return-different-paths
Sys.setenv(PATH = paste0("/Users/username/.cargo/bin:", Sys.getenv("PATH")))确保" username“是您的用户名。例如,我的路径是"/Users/tommy/.cargo/bin:“
这会将default location of Rust installation附加到R在启动时接收的$PATH变量。
https://stackoverflow.com/questions/66271292
复制相似问题