简体   繁体   English

语法错误(在R脚本中)

[英]syntax errors (in R-script)

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. (是的,我的wifi已打开= P haha​​)我正在使用BASH构建用于DNA分析的管道,在其中使用此脚本真的很有用。 (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. (我将其制作的功劳记为0%,但已发布给所有人使用) https://forum.qiime2.org/t/automatic-manifest-maker-in-r/2921我从未做过任何工作在R中再次如此,如果这是一个愚蠢的问题,我感到抱歉。

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)

here are the errors 这是错误

/home/qiime2/Taxonomy.R: line 1: syntax error near unexpected token `tidyverse'
/home/qiime2/Taxonomy.R: line 1: `library(tidyverse)'

Just to add some context, this is in a Ubuntu VM, the following commands were run to install and set up the packages 只是为了添加一些上下文,这是在Ubuntu VM中,运行以下命令来安装和设置软件包

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

I called the script Taxonomy.R and gave it chmod +x it was created and is currently in the ~ directory 我将脚本命名为Taxonomy.R,并将其命名为chmod + x,该脚本已创建,当前位于〜目录中

When running an R script as an executable file, you need to add a "shebang" (see, for example, this discussion ); 当将R脚本作为可执行文件运行时,您需要添加一个“ shebang”(例如,参见本讨论 )。 so, as the very first line of your R script, add the following: 因此,作为R脚本的第一行,添加以下内容:

#!/usr/bin/env Rscript

Then, from the terminal, you should be able to run 然后,从终端,您应该可以运行

source activate R-Env
./Taxonomy.R

(See a brief discussion of shebangs and Anaconda in a different context at this Stack Overflow question ). (请参阅此Stack Overflow问题中有关上下文的shebangs和Anaconda的简短讨论)。 Note that you may need to deactivate then reactivate your R-Env for this to work. 请注意,您可能需要先停用然后重新激活R-Env才能起作用。

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脚本运行,但不能保证您的R脚本将运行而不会发生不相关的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM