1

I'm using a snakemake which call an R script , but I'm getting this error :

Error in isOpen(file, "w") : invalid connection
Calls: write.table -> isOpen
Execution halted

my rule in snakemake is :

rule prepare_files:
input: 
       x = "path_to_x/quant.sf", 
       y = "path_to_Y/quant.sf"
output: 
       "out//Bigquantif.txt"   
script:
   "R/manips.R"

In manips.R i have :

out_file_path <- snakemake@output
x_path <-snakemake@input$x
y_path <-snakemake@input$y
x_fi <- read.table(x_path, head=T, sep="\t", row.names=1)
y_fi <- read.table(y_path, head=T, sep="\t", row.names=1)
merged_data_final <- merge(x_fi, y_fi, by = "gene_id")
write.table(x = merged_data_final, file = out_file_path, sep="\t")

I tried with write.csv and csv2 but always the same error !!

If any one can help, I will be thankful

I was expecting that was a problem of access rights on the repertory i changed it by chmod +x but this didn'nt fixe it

zx8754
  • 52,746
  • 12
  • 114
  • 209
Dima's
  • 21
  • 2
  • I think you need `x_path <- snakemake@input[['x']]`, see related post: https://stackoverflow.com/a/68620783/680068 – zx8754 Apr 13 '23 at 14:03
  • Also, error suggest you don't have the permission to that folder/file? https://stackoverflow.com/q/17779004/680068 – zx8754 Apr 13 '23 at 14:04
  • 1
    I have seen all those posts and I tried with snakemake@input[['x']] and alse I tested write.csv ranther than write.table and still getting the same error . I checked that the directory have right to read and write – Dima's Apr 13 '23 at 14:58

1 Answers1

0

My issue was I was returning a vector of values rather than a single string. I changed:

out_file_path <- snakemake@output

to:

out_file_path <- snakemake@output[[1]]

and now it works. Hope this will help

L Tyrone
  • 1,268
  • 3
  • 15
  • 24
Dima's
  • 21
  • 2