在 R Studio 中运行多个 R 脚本 [英] Run multiple R Scripts in R Studio

查看:168
本文介绍了在 R Studio 中运行多个 R 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多由 RStudio 创建的 R 脚本,我想知道是否有一种方法可以通过一个步骤在 RStudio 中运行所有这些脚本,而不是打开并逐个运行它们.我知道我可以将它们复制并粘贴到同一个脚本中,但这会使它变得太大,而且这也是一个耗时的步骤.谢谢!

I am having a lot of R Scripts created by RStudio, and I am wondering if there is a method to run all of them in RStudio with a single step instead of open and run each of them one by one.I know that I can copy and paste them together into one same script, but it will make it too large and it's also a time consuming step. Thank you!

推荐答案

您可以拥有一个主脚本,sources 其他脚本,然后只运行主脚本.

You could have one main script that sources the others and just run the main script.

main.R

print("Hello main")
source("blah.R")
source("foo.R")

等等.R

print("Hello blah")

foo.R

print("Hello foo")

<小时>

通过采购main.R

> source("main.R")
[1] "Hello main"
[1] "Hello blah"
[1] "Hello foo"
> ?source

源{base}

source 使 R 接受来自命名文件或 URL 或连接的输入.从该文件读取并解析输入,直到到达文件末尾,然后在所选环境中按顺序计算解析的表达式.

source causes R to accept its input from the named file or URL or connection. Input is read and parsed from that file until the end of the file is reached, then the parsed expressions are evaluated sequentially in the chosen environment.

这篇关于在 R Studio 中运行多个 R 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆