且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Dockerfile中的多行Rscript

更新时间:2023-12-04 14:06:17

BASH会将换行符解释为命令的结尾.

BASH will interpret a newline as the end of the command.

在BASH(我假设您正在使用)中,反斜杠后跟换行符被解释为该行的延续.除非它在单引号内!

In BASH (which I'm assuming you're using), a backslash followed by a newline is interpreted as a continuation of the line. Except when it is inside single quotes!

所以...

Rscript -e 'devtools::install_cran(c("tidytext","janitor",
                          "corrr","officer","devtools","pacman"))'

将被解释为两个命令...

will be interpreted as two commands...

Rscript -e 'devtools::install_cran(c("tidytext","janitor",

"corrr","officer","devtools","pacman"))'

两者都不是正确的格式.

Neither of which are well formed.

此外,BASH中的单引号字符串将无法处理转义.他们只是假设您的文字是文字.因此,您无法在BASH中的单引号字符串内继续一行.

Additionally, single quoted strings in BASH will not handle escapes. They simply assume your text is literal. So you cannot continue a line within single quoted strings in BASH.

最重要的是,如果要在BASH中用引号引起来的字符串内继续,则必须使用双引号引起来的字符串.您的选择如下:

The bottom line is that if you want continuation within a quoted string in BASH, you must use double quoted strings. Your options are as follows:

Rscript -e "devtools::install_cran(c('tidytext','janitor', \  
                'corrr','officer','devtools','pacman'))"

在BASH中使用双引号,在R或...中使用单引号.

using double quotes in BASH and single quotes in R or...

Rscript -e "devtools::install_cran(c(\"tidytext\",\"janitor\", \    
                \"corrr\",\"officer\",\"devtools\",\"pacman\"))"

在两者中都使用双引号.

using double quotes in both.