<p>After checking with <code>file.exists()</code>, I would suggest you try the same command with another SRA run. It may happen that some runs are not accessible for reasons I do not know. I always have problems in accessing sra formatted files and use a workaround to download fastq.</p>
<p>Here is my not official workaround:</p>
<pre><code>runlist&lt;-sraConvert(&quot;SRP045534&quot;,sra_con=sra_con)
runlist[1:2,]

study submission    sample experiment        run
1 SRP045534  SRA179382 SRS685546  SRX681992 SRR1552451
2 SRP045534  SRA179382 SRS685544  SRX681990 SRR1552449

for (dloadrun in runlist$run) 
{
    getSRAfile(dloadrun,sra_con=sra_con,fileType=&quot;fastq&quot;)
}
</code></pre>
<p>This should iteratively download all the runs associated to the project you are studying.
It is possible that you can do the same with sra type file, but I have never been able to use them with sraDB, and never investigated the issue.</p>

CC BY-SA 4.0
2022-04-10T21:26:37.237Z
I am also having this issue- my SQL file comes back as TRUE when I use file.exists but then in Fabio's workaround, the table comes out blank. Same error as you if I use getSRAfile.
hank00000
CC BY-SA 4.0
2021-02-08T08:46:17.553Z
2021-02-08T13:23:20.647Z
2021-02-08T13:23:20.647Z
Fabio Marroni
<p>I am trying to write a code for importing sra files as fastq files in Rstudio (for obtaining and aligning RNA-seq reads from public repositories). I keep getting &quot;Error in if (is.na(sra_acc$run[i])) { : argument is of length zero&quot; right after I run this code. Any suggestions on what might be going wrong? My code is as follows:</p>
<pre><code>library(SRAdb)
sqlfile &lt;-'SRAmetadb.sqlite'
if(!file.exists('SRAmetadb.sqlite')) sqlfile &lt;&lt;- getSRAdbFile()
sra_con &lt;- dbConnect(SQLite(),sqlfile)
sraInf &lt;- getSRAinfo(&quot;SRP045534&quot;,sra_con, sraType=&quot;sra&quot;)

Error in if (is.na(sra_acc$run[i])) { : argument is of length zero
</code></pre>

CC BY-SA 4.0
2021-01-29T20:34:42.457Z
Have you confirmed whether `file.exists('SRAmetadb.sqlite')` is TRUE or FALSE? Or generally, what the value of any of your variables is? I am not familiar with this library but having `sqlfile` be a string that is overwritten by the return value of `getSRAdbFile()` (don't know what that is) seems like it might cause an issue. Also, are you intending to use the superassignment operator (`<<-`)? I believe that you are using it in a non-standard way: https://stat.ethz.ch/pipermail/r-help/2011-April/275905.html
Maximilian Press
<r><sratoolkit>
Error in if (is.na(sra_acc$run[i])) { : argument is of length zero
# Error in if (is.na(sra_acc$run[i])) { : argument is of length zero

(Asked by: username_0 on 2021-01-27)

I am trying to write a code for importing sra files as fastq files in Rstudio (for obtaining and aligning RNA-seq reads from public repositories). I keep getting "Error in if (is.na(sra_acc$run[i])) { : argument is of length zero" right after I run this code. Any suggestions on what might be going wrong? My code is as follows:
library(SRAdb)
sqlfile <-'SRAmetadb.sqlite'
if(!file.exists('SRAmetadb.sqlite')) sqlfile <<- getSRAdbFile()
sra_con <- dbConnect(SQLite(),sqlfile)
sraInf <- getSRAinfo("SRP045534",sra_con, sraType="sra")

Error in if (is.na(sra_acc$run[i])) { : argument is of length zero

**Tags:** r, sratoolkit
> **Comments:**
> **username_1**: Have you confirmed whether `file.exists('SRAmetadb.sqlite')` is TRUE or FALSE? Or generally, what the value of any of your variables is? I am not familiar with this library but having `sqlfile` be a string that is overwritten by the return value of `getSRAdbFile()` (don't know what that is) seems like it might cause an issue. Also, are you intending to use the superassignment operator (`<<-`)? I believe that you are using it in a non-standard way: https://stat.ethz.ch/pipermail/r-help/2011-April/275905.html  

---

## 1 answers

### Answer by username_2 on 2021-02-08. Score: 2

After checking with file.exists(), I would suggest you try the same command with another SRA run. It may happen that some runs are not accessible for reasons I do not know. I always have problems in accessing sra formatted files and use a workaround to download fastq.
Here is my not official workaround:
runlist<-sraConvert("SRP045534",sra_con=sra_con)
runlist[1:2,]

study submission    sample experiment        run
1 SRP045534  SRA179382 SRS685546  SRX681992 SRR1552451
2 SRP045534  SRA179382 SRS685544  SRX681990 SRR1552449

for (dloadrun in runlist$run) 
{
    getSRAfile(dloadrun,sra_con=sra_con,fileType="fastq")
}

This should iteratively download all the runs associated to the project you are studying.
It is possible that you can do the same with sra type file, but I have never been able to use them with sraDB, and never investigated the issue.

> **Comments:**
> **username_3**: I am also having this issue- my SQL file comes back as TRUE when I use file.exists but then in Fabio's workaround, the table comes out blank. Same error as you if I use getSRAfile.  

---

