有使用Windows 10在R Markdown上运行bash脚本的简便方法吗? [英] Is there an easy way to run bash scripts on R Markdown, using Windows 10?
问题描述
过去几个月我一直在学习R Markdown.让Anaconda Python在R Markdown脚本中运行相当容易,但是我还没有找到在同一文档中运行bash代码块的方法.
I've been learning R Markdown for the past months. It was fairly easy to get Anaconda Python to run within a R Markdown script, but I haven't yet found a way to get to run chunks of bash code within the same document.
使用
```{bash}
echo hello world
```
我收到错误消息
/bin/bash:C:\ Users \ MyName \ AppData \ Local \ Temp \ Rtmp0MpNfS \ chunk-code-4cbc213a3545.txt:无此类文件或目录
/bin/bash: C:\Users\MyName\AppData\Local\Temp\Rtmp0MpNfS\chunk-code-4cbc213a3545.txt: No such file or directory
你们中的任何人都可能知道这个问题的根源吗?
Might any of you guys know what might be the root of this problem?
推荐答案
我知道可能已经晚了,但是我遇到了同样的问题,我找到了解决方法.
I know maybe is to late but I had the same problem and I find the solution.
首先,在Windows 8.1中,或者如果您没有Windows Linux子系统(WSL),则可以安装 Cygwin : https://cygwin.com/>安装Cygwin
First, in Windows 8.1 or if you don´t have the Windows Subsystem for Linux (WSL) you can install Cygwin: https://cygwin.com/ > Install Cygwin
- 这是 R Markdown:权威指南( https://bookdown .org/yihui/rmarkdown/)> 2.7其他语言引擎> 2.7.2 Shell脚本
- This is the recommendation pointed out in R Markdown: The Definitive Guide (https://bookdown.org/yihui/rmarkdown/) > 2.7 Other language engines > 2.7.2 Shell scripts
第二,将Cygwin添加到PATH.通常,Cygwin安装在C:\cygwin64
中,在这种情况下,包含路径将为C:\cygwin64\bin
Second, add Cygwin to the PATH. Usually Cygwin is installed in C:\cygwin64
and the path to include will be in this case C:\cygwin64\bin
第三,使用R中的base::Sys.which("bash")
检查一切是否正确
Third, check that everything is correct using base::Sys.which("bash")
in R
- 如果一切正确,它将显示如下内容
"C:\\cygwin64\\bin\\bash.exe"
第四,您可以在Rmarkdown文档中运行,您已指出要仔细检查的块:
Fourth, you can run in a Rmarkdown document, the chunk that you pointed out to double check:
```{bash}
echo hello world
```
这篇关于有使用Windows 10在R Markdown上运行bash脚本的简便方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!