R:使用 system() 调用的别名命令

标签 r bash

在我的 ~/.bash_profile 文件中,我放置了这个 alias 命令:

which mvsync
alias mvsync='rsync --remove-source-files -arvuP'
    /usr/bin/rsync

它在 bash shell 中工作正常,但是当我在 R 中使用 system 调用它时,我得到一个命令未找到:

R
system('mvsync --help')
sh: mvsync: command not found

## Or
system('mvsync --help', intern=TRUE)
sh: mvsync: command not found
Error in system("mvsync --help", intern = TRUE) : 
  error in running command

## Or
system("bash -i -c mvsync")
bash: mvsync: command not found

[4]+  Stopped                 R

bash_profile 中的其他环境变量被 R/system() 正确识别。 知道如何/是否可以修复它吗?

这是 R session 信息:

sessionInfo()
R version 3.1.3 (2015-03-09)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: CentOS release 6.6 (Final)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] graphics  grDevices utils     datasets  stats     methods   base     

other attached packages:
[1] ggplot2_1.0.0    data.table_1.9.4

loaded via a namespace (and not attached):
 [1] chron_2.3-45     colorspace_1.2-4 digest_0.6.8     grid_3.1.3       gtable_0.1.2     MASS_7.3-39      munsell_0.4.2    plyr_1.8.1       proto_0.3-10     Rcpp_0.11.3      reshape2_1.4     scales_0.2.4     stringr_0.6.2   

最佳答案

您的 shell 可能不是登录 shell:http://linux.die.net/man/1/bash

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.

--登录可能有效,但最好将您的别名放在 .bashrc 中,即使它不是登录 shell 也会执行

关于R:使用 system() 调用的别名命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30305973/

相关文章:

r - 将 dplyr summarise_each() 与 is.na() 一起使用

bash - 如何检测 bash 中可能包含空格的空字符串?

linux - 只打印第一个和最后一个匹配的模式

arrays - 如何在循环的 shell 脚本中使用两个数组?

bash - 让 docker 容器永远运行,同时能够优雅地停止

r - R中列表的交集

r - 使用交易信号计算金融时间序列的返回

与 r 的秩双序列相关

r - 使用 2 个数据框进行计算

linux - Bash 将多行 Git 日志输出保存到环境变量