Rhea Bedi
Rhea Bedi

Reputation: 129

execution halted as the script is not able to read the file

I am running a script in R using command: Rscript gtex_tiss_chrom.R 1 The content of this script is:

source("../code/gtex_v7_nested_cv_elnet.R")
"%&%" <- function(a,b) paste(a,b, sep='')

argv <- commandArgs(trailingOnly = TRUE)
chrom <- argv[1]

#tiss <- argv[1]
#chrom <- argv[2]

snp_annot_file <- "../output/snp_annot.chr" %&% chrom %&% ".txt"
gene_annot_file <- "../output/gene_annot.parsed.txt"
genotype_file <- "../output/genotype.chr" %&% chrom %&% ".txt"
expression_file <- "../output/transformed_expression.txt"
covariates_file <- "../output/covariates.txt"
prefix <- "Model_training"

main(snp_annot_file, gene_annot_file, genotype_file, expression_file, covariates_file, as.numeric(chrom), prefix, null_testing=FALSE)

the error: Error in file(file, "rt") : cannot open the connection Calls: main ... get_filtered_snp_annot -> %>% -> distinct -> filter -> read.table -> file In addition: Warning message: In file(file, "rt") : cannot open file 'snp_annot.chrNA.txt': No such file or directory Execution halted

Upvotes: 0

Views: 155

Answers (1)

Nic3500
Nic3500

Reputation: 8621

Based on the discussion in the comments, here is the answer.

In the code:

  1. chrom <- argv[1]: assigns the first argument to the chrom variable.
  2. snp_annot_file <- "../output/snp_annot.chr" %&% chrom %&% ".txt". This will assign the filename "../output/snp_annot.chr<VALUE OF CHROM>.txt".
  3. If argv[1] is not assigned, chrom would be assigned NA.
  4. Hence the filename is built as "../output/snp_annot.chrNA.txt".
  5. And that file does not exist, hence your error message.

The solution is to modify the code slightly:

  1. If you want to pass the filename to the script, use: snp_annot_file <- chrom.
  2. That way the value of the argument you used gets used directly.
  3. OR you could hard code the filename in the scrip, depending on your requirement.

FYI:

  1. The same applies to this second line: snp_annot_file <- "../output/snp_annot.chr" %&% chrom %&% ".txt"

Upvotes: 1

Related Questions