I am using a program that requires me to load a "sam" file. However, the code given does not create the data.file
variable necessary and instead produces ""
, a blank instead.
This is the code given:
data.file <- system.file(file.path('extdata', 'vignette-sam.txt'), package='flipflop')
I put in:
data.file <- system.file(file.path("Users", "User1", "Desktop", "Cond_18",
"Sorted_bam_files", "Cond_18_1.bam_sorted.sam"),
package='flipflop')
The path is definitely correct and the package name is flipflop
. However every time I check what the variable data.file
is, it produces ""
. So the file is never being loaded and the script can't run.
I also put in the entire file path into one version of it:
data.file <- system.file('/Users/User1/Desktop/Cond_18/Sorted_bam_files/DBM_18_1.bam_sorted.sam',
package='flipflop')
That version does not include file.path
, but it is one of the script examples.
The line in the code that uses these variables is this:
if(preprocess.instance==''){
print('PRE-PROCESSING sam file ....')
data.file <- path.expand(path=data.file) # In case there is a '~' in the input path
if(data.file==''){ print('Did you forget to give a SAM file?') ; return(NULL) }
annot.file <- path.expand(path=annot.file)
samples.file <- path.expand(path=samples.file)
And since data.file is ""
it defaults to NULL
.
You use system.file
when the file you want to reference is from a package. Here is what the help file for system.file
says:
Finds the full file names of files in packages etc.
You just want to reference a file on your machine. You can just directly store the path and use that as your data.file
data.file <- "C:/path/to/your/file"
The script uses file.path
because it's a safer way to generate paths in a platform-independent way. For example:
> file.path("C:", "Users", "BotsRule", "Code", "myawesomeRscript.R")
[1] "C:/Users/BotsRule/Code/myawesomeRscript.R"
So the solution to your problem is to just make sure you're actually doing something just anything to correctly specify the path to your file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With