语法错误(在 R 脚本中) [英] syntax errors (in R-script)
问题描述
我很抱歉这篇文章,我确定它太简单了,但我一直在寻找,找不到任何答案!(是的,我的 wifi 已打开 =P 哈哈)我正在使用 BASH 构建用于 DNA 分析的管道,在其中使用此脚本会非常有用.(我对其制作收取 0% 的功劳,但已发布供所有人使用)https://forum.qiime2.org/t/automatic-manifest-maker-in-r/2921我以前从未在 R 中做过任何工作,所以如果这是一个愚蠢的问题,我很抱歉.
I'm very sorry about this post, I'm sure its way too simple but I've been looking and looking and can't find any answers! (yes my wifi is switched on =P haha) I'm building a pipeline for DNA analysis using BASH and it would be really useful to use this script in it. (I take 0% of the credit for its making but it has been posted for all to use) https://forum.qiime2.org/t/automatic-manifest-maker-in-r/2921 I have never done any work in R before so again I'm sorry if this is a dumb question.
我怀疑问题出在前几行或解释方式上,这里是前 3 行
I suspect the issue is with the first few lines or perhaps the way its being interpreted, here are the first 3 lines
library(tidyverse)
SamplesF <- list.files(path = "Data", pattern = "*.R1.fastq.gz", all.files =
FALSE,
full.names = TRUE, recursive = FALSE,
ignore.case = FALSE, include.dirs = FALSE, no.. = FALSE)
这里是错误
/home/qiime2/Taxonomy.R: line 1: syntax error near unexpected token `tidyverse'
/home/qiime2/Taxonomy.R: line 1: `library(tidyverse)'
只是添加一些上下文,这是在 Ubuntu VM 中,运行以下命令来安装和设置软件包
Just to add some context, this is in a Ubuntu VM, the following commands were run to install and set up the packages
conda create -n R-Env -y
source activate R-Env
Install r-essentials and tidyverse package by running:
conda install r-essentials -y
conda install -c r r-tidyverse -y
conda install -c r r-gdata -y
我调用了脚本 Taxonomy.R 并给了它修改 +x它已创建,目前在 ~ 目录中
I called the script Taxonomy.R and gave it chmod +x it was created and is currently in the ~ directory
推荐答案
当将 R 脚本作为可执行文件运行时,您需要添加一个shebang"(例如,请参见 这个讨论);因此,作为 R 脚本的第一行,添加以下内容:
When running an R script as an executable file, you need to add a "shebang" (see, for example, this discussion); so, as the very first line of your R script, add the following:
#!/usr/bin/env Rscript
然后,从终端,您应该可以运行
Then, from the terminal, you should be able to run
source activate R-Env
./Taxonomy.R
(在这个堆栈溢出问题).请注意,您可能需要停用然后重新激活您的 R-Env
才能使其工作.
(See a brief discussion of shebangs and Anaconda in a different context at this Stack Overflow question). Note that you may need to deactivate then reactivate your R-Env
for this to work.
虽然这将解决语法错误并允许您的 R 脚本运行,但并不能保证您的 R 脚本运行时不会出现不相关的错误.
While that will solve the syntax error and allow your R script to run, it does not guarantee your R script will run without unrelated errors.
这篇关于语法错误(在 R 脚本中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!