0

I am trying to open a Granges file, and I want to store it under a specific name rather than the file name so that I can later use the file within functions and loops. The following works fine, but saves the file under the name 'grs'.

load("~/data/grs_xxx.Rdata")
> head(grs)

GRanges object with 6 ranges and 0 metadata columns:
         seqnames      ranges strand
            <Rle>   <IRanges>  <Rle>
  [1] NC_007070.3 27001-27100      *
  [2] NC_007070.3 27051-27150      *
  [3] NC_007070.3 27101-27200      *
  [4] NC_007070.3 27151-27250      *
  [5] NC_007070.3 27201-27300      *
  [6] NC_007070.3 27251-27350      *
  -------

If I try to assign it;

    test <- load("~/data/grs_xxx.Rdata")
> head(test)
[1] "grs"

Is there a way around this that doesn't affect the Granges table?

Harnarday
  • 21
  • 7

1 Answers1

0

I haven't been able to find a direct way of resolving this problem using only load() but I can use this work around that I found;

How can I load an object into a variable name that I specify from an R data file?

User Ricardo posts;

loadRData <- function(fileName){
#loads an RData file, and returns it
   load(fileName)
   get(ls()[ls() != "fileName"])
}
d <- loadRData("~/blah/ricardo.RData")
Harnarday
  • 21
  • 7