gpt4 book ai didi

r - 使 R 项目自动打开特定脚本

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

我在团队中工作,我们主要使用 R,我非常习惯在 Rstudio 中使用 R 项目,我喜欢它,因为当我打开它们时,我的所有脚本和所有内容都在正确的位置。但是,当团队的另一名成员打开我的一个项目时,它会加载值和数据,但不会打开 R 脚本(可以通过 Windows 资源管理器物理单击项目而不是使用右上角的菜单来查看这一点) R)。我想可以在 .Rprofile 中完成一些操作,但我没有找到任何物理打开脚本的命令,我试过了

file.edit("./Main.R") 

但它没有打开任何东西。它刚刚给我的消息:

Error: could not find function "file.edit"



一如既往,
谢谢你的帮助 !

**编辑
我试着用
file.show
file.edit
shell.exec(file.path(getwd()), "Main.R"))

在 .Rprofile 中。没有任何效果。

罗曼

最佳答案

您可以在 .Rprofile 文件中使用以下代码。

setHook("rstudio.sessionInit", function(newSession) {
if (newSession)
rstudioapi::navigateToFile('<file name>', line = -1L, column = -1L)
}, action = "append")

rstudioapi 库具有navigateToFile 函数,可以在Rstudio 中打开文件。问题是 .Rprofile 中的代码在 Rstudio 初始化之前运行。为了解决这个问题,你可以使用 setHook 函数(来自基础包)让代码在 Rstudio 初始化后执行。

关于r - 使 R 项目自动打开特定脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26473205/

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