Load data "namespace not available" - r

I have received a bunch of data saved with the save function of R.
When I try to load it, I got a Warning about the namespace and so finally an error. Is there a way to sort that out and to recover the data ?
> load('mydata')
Warning: namespace ‘BMP’ is not available and has been replaced
by .GlobalEnv when processing object ‘res’
Error: ReadItem: unknown type 0, perhaps written by later version of R
I know that BMP is a function used to generate the data, and that res is one of the elements contained in mydata.

Related

Is there a way to get a list of the R objects in a file you're using load() on? If so, is it possible to load them individually?

Trying to load() a file that ends up giving me an error:
load('.RDataTmp', verbose = T)
Loading objects:
object1
object2
object3
object4
object5
Error in load(".RDataTmp", verbose = T) : error reading from connection
when I try to load it. Obviously, I messed up the name when I was saving this originally, but just when messing around I was able to save and load other objects with similarly messed up names. But it's appearing to load some of the objects before failing at loading some later object (secondary question, does this mean it loaded object5 successfully, or that's where the error occurred?). Is there a way to get a list of all the objects in the file? Then, is there a way to try and load only some of the objects?

Why does wrapper function result in error

I'm trying to include a function from the Bioconductor package "simpIntLists" in my own package. "import(simpIntLists)" is added to the Namespace file.
However, the function results in an error
do_xy <- function(organism, IDType){
network <- simpIntLists::findInteractionList(organism, IDType)
}
do_xy("human", "EntrezId")
#Error message
data set ‘HumanBioGRIDInteractionEntrezId’ not foundError in get("HumanBioGRIDInteractionEntrezId") :
object 'HumanBioGRIDInteractionEntrezId' not found
# results in the same error (outside of the function)
simpIntLists::findInteractionList(organism, IDType)
It works fine when simpIntLists is attached
# works
library(simpIntLists)
network <- simpIntLists::findInteractionList(organism, IDType)
I saw the code here (https://bioconductor.org/packages/release/data/experiment/html/simpIntLists.html).
This code does not seem to take into account the situation where the package is used without installation.
For your information, the relevant part to this error is around the line 52.
else if (organism == 'human'){
if (idType == 'EntrezId'){
data(HumanBioGRIDInteractionEntrezId);
interactionList <- get("HumanBioGRIDInteractionEntrezId");
}
It tries to fetch the data to the namespace but it fails to do so if the package is not imported via library yet. This only generates a warning. The error then occurs when it tries to use the data because it does not exist in the namespace.
A workaround is that you import the data in your code explicitly. Then you can use the function as below. Note that the warning remains because of the embedded package code. If the warning is annoying, use suppressWarnings.
data(HumanBioGRIDInteractionEntrezId, package="simpIntLists")
simpIntLists::findInteractionList("human", "EntrezId")

Difficulty opening a package data file of unknown type

I am trying to load the state map from the maps package into an R object. I am hoping it is a SpatialPolygonsDataFrame or something I can turn into one after I have inspected it. However I am failing at the first step – getting it into an R object. I do not know the file type.
I first tried to assign the map() output to an R object directly:
st_m <- maps::map(database = "state")
draws the map, but str(st_m) appears to do nothing, unless it is redrawing the same map.
Then I tried loading it as a dataset: st_m <- data("stateMapEnv", package="maps") but this just returns a string:
> str(stateMapEnv)
chr "R_MAP_DATA_DIR"
I opened the maps directory win-library/3.4/maps/mapdata/ and found what I think is the map file, “state.L”.
I tried reading it with scan and got an error message I do not understand:
scan(file = "D:/Documents/R/win-library/3.4/maps/mapdata/state.L")
Error in scan(file = "D:/Documents/R/win-library/3.4/maps/mapdata/state.L") :
scan() expected 'a real', got '#'
I then opened the file with Notepad++. It appears to be a binary or compressed file.
So I thought it might be an R data file with an unusual extension. But my attempt to load it returned a “bad magic number” error:
st_m <- load("D:/Documents/R/win-library/3.4/maps/mapdata/state.L")
Error in load("D:/Documents/R/win-library/3.4/maps/mapdata/state.L") :
bad restore file magic number (file may be corrupted) -- no data loaded
Observing that these responses have progressed from the unhelpful through the incomprehensible to the occult, I thought it best to seek assistance from the wizards of stackoverflow.
This should be able to export the 'state' or any other maps dataset for you:
library(ggplot2)
state_dataset <- map_data("state")

Error when loading an .mat file using R

I try to load a .mat file using the R.matlab library. When I run:
x <- readMat("MPL.mat")
I get this error however.
Error in mat5ReadTag(this) :
Unknown data type. Not in range [1,19]: 18569
In addition: Warning message:
In readMat5Header(this, firstFourBytes = firstFourBytes) :
Unknown MAT version tag: 512. Will assume version 5.
Anybody who experienced this and has a way to deal with this?
Im familiar with this post: R.matlab/readMat : Error in readTag(this) but alternatives ways didnt work for me...
The problem is related to how is saved your "MPL.mat". If you save by default in MATLAB, it probably won't work using R.matlab in R.
When I saved my .mat object in '-v7' or '-v6' i did not have problems, but the R.matlab documentation suggest to save in '-v6' (Pag.25 in R.matlab package). For example, I saved 2 matrices (A and B) in 'MPL.mat'.
save('MPL.mat','A', 'B', '-v7')
I could read in R:
require(R.matlab)
data <- readMat("MPL.mat")
View(data$A)
View(data$B)

Error in exprs(eset)

I am trying to read probes from a dat file, put them in a vector then put the vector into a subset to be able to concatenate more data to it and write it in a CSV file. Here my piece of code:
library(Biobase)
library(affy)
affys <- read.csv("address of my dat file")
affys_vec <- as.vector(affys)[,1]
exprs(eset)[affys_vec,] -> sub.set
write.csv(sub.set,file="subset.csv")
However when I reach to the : exprs(eset)[affys_vec,] -> sub.set
I get the following error message:
** Error in exprs(eset) :
error in evaluating the argument object' in selecting a method for function 'exprs':
Error: object 'eset' not found **
Are there any suggestions please?
Thanks,
pqtm
See the vignette An introduction to Biobase and ExpressionSets available on your computer, once Biobase is installed, as
vignette(package="Biobase", "ExpressionSetIntroduction")
But the idea is that you have created eset by pre-processing some CEL or other vendor-specific files. How you pre-process those depends on what your files are, maybe with affy or oligo or lumi, or from a public repository using a package like ArrayExpress or GEOquery Or perhaps you're using limma and have no need for an expression set.
The Bioconductor web site and mailing list provides a lot more information.

Resources