如何从 RStudio 的内置 R 控制台中 运行 R 脚本?
How do I run an R script from within RStudio's built-in R console?
我假设它类似于 Python 的 import
声明,但我想快速回答一下,因为我正在介绍 class 对现在。
这是我得到的最接近的,但它似乎与问题不符,因为它显示了如何从系统 CLI,而不是蓝色 RStudio >
运行 R 脚本提示:
Run an R-script from command line and store results in subdirectory
如果您想 运行 R 脚本中的特定行,请将光标放在行中的某个位置,然后按 command+enter(在其他电脑上我认为是 ctrl+enter)。如果您想 运行 整个脚本或某些部分,select 该部分和命令+输入。
使用 source() 函数的简短回答
一旦你download, install, and open the RStudio, you'll see a part in the lower left with blue greater than symbols >.
在RStudio的GUI蓝色部分>
,输入以下内容
> setwd('/folder/where/the/file/is/')
> source('file_name')`
...output, if any, appears below...
示例:
假设我在 /home/myusername/prj/r/learn_r/insurance_data.r
有一个文件,我想 运行.
我会启动 RStudio,然后在标有 Console 的小 window 中输入以下内容:
带有使用 source() 函数的屏幕截图的烦人长答案
好吧,事实证明它比我从 RStudio 的 built-in 控制台 运行 预期的要简单得多。我很惊讶以前没有人问过关于 RStudio 的问题。如果有,我想我会有一个急切的问题。
无论如何,一点点尝试和错误告诉我如何做到这一点:
是的,下面出现了输出。
确保首先设置您的工作目录。
我在我的 Ubuntu 16.04 LTS 环境中从 RStudio 1.0.143 内部按如下方式执行此操作:
setwd("~/proj/r/learn_r")
接下来可以输入help(source)
,搜索source()
函数的语法,直接在RStudio控制台输入提示即可:
我假设它类似于 Python 的 import
声明,但我想快速回答一下,因为我正在介绍 class 对现在。
这是我得到的最接近的,但它似乎与问题不符,因为它显示了如何从系统 CLI,而不是蓝色 RStudio >
运行 R 脚本提示:
Run an R-script from command line and store results in subdirectory
如果您想 运行 R 脚本中的特定行,请将光标放在行中的某个位置,然后按 command+enter(在其他电脑上我认为是 ctrl+enter)。如果您想 运行 整个脚本或某些部分,select 该部分和命令+输入。
使用 source() 函数的简短回答
一旦你download, install, and open the RStudio, you'll see a part in the lower left with blue greater than symbols >.
在RStudio的GUI蓝色部分>
,输入以下内容
> setwd('/folder/where/the/file/is/')
> source('file_name')`
...output, if any, appears below...
示例:
假设我在 /home/myusername/prj/r/learn_r/insurance_data.r
有一个文件,我想 运行.
我会启动 RStudio,然后在标有 Console 的小 window 中输入以下内容:
带有使用 source() 函数的屏幕截图的烦人长答案
好吧,事实证明它比我从 RStudio 的 built-in 控制台 运行 预期的要简单得多。我很惊讶以前没有人问过关于 RStudio 的问题。如果有,我想我会有一个急切的问题。
无论如何,一点点尝试和错误告诉我如何做到这一点:
是的,下面出现了输出。
确保首先设置您的工作目录。
我在我的 Ubuntu 16.04 LTS 环境中从 RStudio 1.0.143 内部按如下方式执行此操作:
setwd("~/proj/r/learn_r")
接下来可以输入help(source)
,搜索source()
函数的语法,直接在RStudio控制台输入提示即可: