0

This is the top of my R script which was shared on qiime forums. The script is meant to make a metadata file for multiple fastq files. How do I edit it to run without needing editing every time but I cant seem to tell it to use the current working director

Here is the problem code:

#!/usr/bin/env Rscript
library(tidyverse)

data_path <- paste ("./", "Data", sep = "/")

And its error:

Error in `[<-.data.frame`(`*tmp*`, "direction", value = "forward") : 
  replacement has 1 row, data has 0
Calls: [<- -> [<-.data.frame
Execution halted
Gus Bishop
  • 23
  • 6
  • I think you're looking for `setwd()`. Am I right in thinking you always want to set the working directory to "./Data/" ? If so, `setwd("Data/")` should work. – forestfanjoe Sep 27 '18 at 13:50
  • Also - and I don't know anything about conda installed R-Env - but I think you're curly double quotes might be messing up your code. – forestfanjoe Sep 27 '18 at 13:53
  • so I changed the line starting `datapath` to; `data_path <- paste (setwd("Data/"), "Data", sep = "/") I got a similar error; `unexpected input in "data_path <- paste (setwd("Data/") �" – Gus Bishop Sep 27 '18 at 14:07
  • Hello Gus, welcome to stack overflow. I think the error is caused by "wrong" quotation-marks. If you take a close look on them they are not the standard quotation marks but some other characters. So R doesn't read them as quotation-mark and therefore the text between not as a string but some object. Just deleat them and make them new and you should have a running line of code. (just for comparision: the quotemarke used: “ and the standard one ") – TinglTanglBob Sep 27 '18 at 14:12
  • just as @ forestfanjoe allready explained but i didn't read before posting :D shame on me. – TinglTanglBob Sep 27 '18 at 14:19
  • I think you're definitely onto something, but its not fixed it ='( – Gus Bishop Sep 27 '18 at 14:26
  • `#!/usr/bin/env Rscript library(tidyverse) data_path <- paste "(setwd(Data/)" "Data", sep = "/") SamplesF <- list.files(path = data_path, pattern = “*.R1.fastq.gz”, all.files = FALSE, full.names = TRUE, recursive = FALSE, ignore.case = FALSE, include.dirs = FALSE, no… = FALSE)` – Gus Bishop Sep 27 '18 at 14:27
  • `── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ── ✖ dplyr::filter() masks stats::filter() ✖ dplyr::lag() masks stats::lag() Error: unexpected string constant in "data_path <- paste "(setwd(Data/)"" Execution halted (R-Env) qiime2@qiime2core2018-8:~/nanopore_reads/outputs/workspace/pass/barcode01$ ` – Gus Bishop Sep 27 '18 at 14:27
  • `Error: unexpected string constant in "data_path <- paste "(setwd(Data/)"" Execution halted ` – Gus Bishop Sep 27 '18 at 14:29
  • Thanks btw, I cannot believe I've never been on stack overflow before, its so cool and everyone (so far) has been super helpful and friendly! – Gus Bishop Sep 27 '18 at 14:30

2 Answers2

1

To set the working directory to the Data folder:

setwd("Data/")
forestfanjoe
  • 412
  • 4
  • 11
0

Thankyou @forestfanjoe and @TingleTanglBob for the help For anyone wondering how a setwd should be formatted see this working example =)

data_path <- paste (setwd ("Data/"),"Data", sep = "/")

Gus Bishop
  • 23
  • 6