R-script, issue with data_path <- paste

218 Views Asked by At

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
2

There are 2 best solutions below

2
On

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 = "/")

0
On

To set the working directory to the Data folder:

setwd("Data/")