0

i am trying to pass external arguments to R when calling a Rscript with a command line in that i am getting an Error in setwd(args[8]) : cannot change working directory Execution halted

Not sure why this error is occurring Please suggest some ideas to sort out

Any idea would be appreciated

Rscript /home/mike/learn-analysis/SL_input.R chr21 10542449 10542649 + Y Y 1 /mnt/prep/learn/CA-21-10542394-10542448.2.D.txt D /home/mike/learn-analysis/SL_table.R

#SL_table.R file

 args <- commandArgs(trailingOnly = TRUE)

setwd(args[8]) # directory to write file to

source(args[11]) # can be updated to reflect location of source code

results<-SL_mutate(args[1],args[2],args[3],args[4],args[5],args[6],args[7]) # chrom, start, stop, strand, gene, transcript, exon number

results$type<-args[10]

results$transcript<-NULL

results$exon_num<-NULL

write.table(results,args[9],quote = F, row.names = F, sep="\t") # write to filename given in argument (in working directory)
Jerry Vfc
  • 75
  • 7
  • 1
    The .R file counts as one arg so try ``args[9]``. But you can debug your own script by printing the args like ``print(args[8])`` to see what's being read in and assigned to what – user438383 Sep 23 '22 at 08:57
  • 1
    And, as an aside, changing the working directory is generally considered to be [poor practice](https://stackoverflow.com/questions/73489216/choose-working-directory-in-code-option-of-r-chunk#73489216). – Limey Sep 23 '22 at 09:04
  • @user438383 print(args[8]) "/mnt/prep/learn/CA-21-10542394-10542448.2.D.txt" for print(args[9]) "D" and print(args[10]) /home/mike/learn-analysis/SL_table.R – Jerry Vfc Sep 23 '22 at 10:11

0 Answers0