← 返回命令列表

Linux command

rscript 命令

网络

复制后可按需替换文件名、目录或参数。

常用示例

Run R script

Rscript [script.R]

Run with arguments

Rscript [script.R] [arg1] [arg2]

Run expression

Rscript -e "[print('hello')]"

Vanilla mode (no init)

Rscript --vanilla [script.R]

Set library path

Rscript --default-packages=[ggplot2,dplyr] [script.R]

说明

Rscript is the non-interactive command-line interface for running R scripts and expressions. It is designed for scripting and automation, providing direct execution of R code files with proper exit codes and shebang support (#!/usr/bin/env Rscript) for use as executable scripts. The -e flag evaluates inline R expressions, useful for one-liners and pipeline integration. Command-line arguments passed after the script name are accessible within R via commandArgs(). The --vanilla flag suppresses loading of saved workspaces and startup files for clean, reproducible execution. Rscript is faster and more convenient than the older R CMD BATCH approach, as it writes output directly to stdout/stderr and returns meaningful exit codes for integration with shell scripts and CI/CD pipelines.

参数

-e _EXPR_
Execute expression.
--vanilla
No saved data or init.
--default-packages _PKGS_
Load packages.
--verbose
Verbose startup.
--no-init-file
Skip .Rprofile.
--save
Save workspace.

FAQ

What is the rscript command used for?

Rscript is the non-interactive command-line interface for running R scripts and expressions. It is designed for scripting and automation, providing direct execution of R code files with proper exit codes and shebang support (#!/usr/bin/env Rscript) for use as executable scripts. The -e flag evaluates inline R expressions, useful for one-liners and pipeline integration. Command-line arguments passed after the script name are accessible within R via commandArgs(). The --vanilla flag suppresses loading of saved workspaces and startup files for clean, reproducible execution. Rscript is faster and more convenient than the older R CMD BATCH approach, as it writes output directly to stdout/stderr and returns meaningful exit codes for integration with shell scripts and CI/CD pipelines.

How do I run a basic rscript example?

Run `Rscript [script.R]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -e _EXPR_ do in rscript?

Execute expression.