I realize that this is a long shot, but did you ever find a fix to this? I'm getting the same error but samtools seems to be installed correctly. I can run it in terminal but R can't find it.
The original answer still applies. If the package you are trying to use -- which package? -- requires the samtools application to be installed (and discoverable, so somewhere in specified by the PATH environment variable) then you'll need to install samtools independently of R. If you need help doing that, then probably you need to ask somewhere (biostars?) where there is more likely to be relevant expertise.
This is obviously a very late answer but I had a similar error:
sh: samtools: command not found
sh: samtools: command not found
Warning message: In FUN(X[[i]], ...) : error in running command
And here is how I fixed it (in case someone ends up here years later like me):
For a bit of context, samtools was correctly installed via conda and I have been using it by itself. So I tried installing samtools again but this time using the installation described on the manual on the official website directly and it was working fine on my terminal; but still not with RStudio for a package that requires samtools.
So here is how you can make sure R is looking in the right directories where your tools are installed (type this in R):
Sys.getenv("PATH")
I noticed it did not contain any of the paths where samtools was installed.
So using the following command you can add a directory to your PATH:
samtools isn't R software, so you would have to install it independently of R. This might be 'hard' on Windows. But maybe the task that you want to accomplish doesn't require the package with the unfriendly dependency on samtools?
I realize that this is a long shot, but did you ever find a fix to this? I'm getting the same error but samtools seems to be installed correctly. I can run it in terminal but R can't find it.
Cheers
The original answer still applies. If the package you are trying to use -- which package? -- requires the samtools application to be installed (and discoverable, so somewhere in specified by the PATH environment variable) then you'll need to install samtools independently of R. If you need help doing that, then probably you need to ask somewhere (biostars?) where there is more likely to be relevant expertise.
Alternatively, if you're trying to access or manipulate BAM files from within R, you might try the Rsamtools or GenomicAlignments (or VariantAnnotation, for VCF) packages.
This is obviously a very late answer but I had a similar error:
And here is how I fixed it (in case someone ends up here years later like me):
For a bit of context, samtools was correctly installed via conda and I have been using it by itself. So I tried installing samtools again but this time using the installation described on the manual on the official website directly and it was working fine on my terminal; but still not with RStudio for a package that requires samtools.
So here is how you can make sure R is looking in the right directories where your tools are installed (type this in R):
I noticed it did not contain any of the paths where samtools was installed. So using the following command you can add a directory to your PATH:
And that's as easy as that (but not obvious if you're not familiar with R like me)!