【发布时间】:2019-12-04 18:10:37
【问题描述】:
当前的R脚本文件被其他程序修改后如何用命令重新加载?
编辑:
假设有一个名为 test.R 的初始文件,其内容如下:
1 # a random number
y <- readLines("test.R") # read the script
x <- as.numeric(y[1]) # convert the number to numeric
x <- x + 1 # increase the number by 1
y[1] <- x # assign the value to y
print(y[1])
writeLines(y, "test.R") # replace the old file by the new file
现在我想重新加载当前文件,以便在文件本身中更新内容。几年来,RStudio 具有重新加载功能,但我不能等到触发 RStudio 的更新信号。我想自己触发。 这是相关的,因为我想编写一个 R 函数,它会自动为xaringan 生成目录。
SO 上的相关问题。
【问题讨论】:
-
不确定你想要什么。 .rs.restartR() 会重启 Rstudio 会话吗?当您在例如 notepad++ 中编辑脚本时,它会在 Rstudio 中自动更新?
-
嘿,谢谢。不,我不谈论重新启动会话。是的,我知道 Rstudio 的重新加载功能,但是当您处于
xaringan的无限月亮阅读器模式时不会触发此功能