I'm quite new to R and I got an assignment that includes a sourcecode.
Part of the source code includes the following line:
library(preprocessCore)
Then I have in my source code a definition of the following function:
quantile.normalize.raw.gtex <- function(edata.mat)
{
norm_edata = normalize.quantiles(as.matrix(edata.mat))
rownames(norm_edata) = rownames(edata.mat)
colnames(norm_edata) = colnames(edata.mat)
return(norm_edata)
}
Finally, I have an object being initialized to the output of this function, after sending a predefined parameter:
tissue.edata.qn = quantile.normalize.raw.gtex(tissue.edata)
From what I understand, the library function is supposed to include the function normalize.quantiles, which is called in the function that is defined in my source code.
However, when I run the line library(preprocessCore) I get the following error:
Error in library(preprocessCore) :
there is no package called ‘preprocessCore’
I also tried to run the rest of the code and got the error:
Error in normalize.quantiles(as.matrix(edata.mat)) :
could not find function "normalize.quantiles"
I looked for the preprocessCore online and eventually I tried to write install.packages("preprocessCore"), but I got a warning message that this package is only available in version 3.6.0 of R, even though I checked and this is the version that I have.
If somebody has any idea what the problem is, I will appreciate your help.
Thanks in advance
The preprocessCore package is available in Bioconductor. So, to install it, you need the following lines:
source("http://bioconductor.org/biocLite.R")
biocLite("preprocessCore")
After that, you can load the package using library(preprocessCore)
Hope it helps.
Related
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")
I'm new to R/web services.
I'm trying to use R's SSOAP package to get/post soap messages.
I want to generate functions definitions using the genSOAPCLientInterface by way of the processWSDL function.
when i run the processWSDL function, i get the following error message, which i dont know how to interpret:
Error in SOAPType(el, namespaceDefs=namespaceDefinitions):could not find function "SOAPType"
any help/pointers would be very helpful.
wsdl_doc<-xmlParse(paste0(wsdl_url, '?wsdl')
definitions<-processWSDL(wsdl_doc, verbose=T, useInternalNodes=T)
Error in SOAPType(el, namespaceDefs = namespaceDefinitions) :
could not find function "SOAPType"
SOAPType is a class used in SSOAP package, but it is declared in package XMLSchema. And for some reason it is not an exported class.
This workaround helped me to make the function processWSDL() working for me:
SOAPType = XMLSchema:::SOAPType
def <- processWSDL(doc)
I tried to run the code in Chapter 7 Data mining with R learning with case study book but I got an error in following line:
rankWorkflows(svm, maxs = TRUE)
The error was:
Error in as.character.default(X[[i]], ...) : no method for coercing
this S4 class to a vector
Then I searched on the internet and found following solution:
importMethodsFrom(GenomicRanges, as.data.frame)
and again again I got a new error:
Error: could not find function "importMethodFrom"
I searched a lot but I got nothing :(
You can try using library(sos) to find the packages where your function is located.
library(sos)
findFn("replaceherewithyourfunction")
Based on the answer of #Bea, there does not seem to be a importMethodsFrom anywhere in R. My guess is you found the call in a NAMESPACE file. Those files have different syntax than normal R scripts.
If you want to load a specific function from an R package (rather than all functions from a package), you can use libraryname::functionname instad of functionname in your code. In your case, replace as.data.frame with GenomicRanges::as.data.frame
If this does not work (for example because you don't have as.data.frame anywhere in your code), you can also load the whole GenomicRanges library with library(GenomicRanges)
I created a package for R to learn how to develop these things and I got a error that I can't resolve. I saw this error was nor uncommon but I could not find a solution.
This is the code of my package (pretty simple):
absconc<-function(x,a,b,...)
{
a<-as.numeric(a)
b<-as.numeric(b)
absconcCalc<- function(x,a,b,...)
{
conc<- (x*a)+b
}
conc<-absconcCalc(x,a,b,...)
print.absconc<- function(x,a,b,...)
{
cat("Slope:")
cat(a,"\n")
cat("Intercept:")
cat(b,"\n")
cat("Concentration:")
cat(conc)
}
print.absconc(x,a,b)
}
I created the package using package.skeleton and it worked like a charm, even the building of the package using R CMD build absconc worked.
The problem was when I trying to use the package it gave me Error: could not find function "absconc".
I though it was a problem coming from NAMESPACE and the export so I tried exporting the functions using export(absconc). When I tried building that I got an error saying:
Error in namespaceExport(ns, exports) :
undefined exports: absconc, absconcCalc, print.absconc
I am now scratching my head to understand why my function are not recognized.
I would appreciate some help on that as this is only my first package.
EDIT: here are my files (A bit messy, sorry)
https://github.com/Frisacher/absconc
You should not edit NAMESPACE by hand. Insert the line #' #export at the top of your R file and run devtools::document() in the console. This will do what is necessary for you.
Now you can execute devtools::load_all() and run your function.
More explicitly:
1) Create a folder named "R" below the root directory and create an R script that contains your function as Martin Morgan suggested in the comments.
2) Add a roxygen comment to your R script to export it:
#' #export
absconc<-function(x,a,b,...)
{
a<-as.numeric(a)
b<-as.numeric(b)
...
}
3) Execute devtools::document() in the console.
> devtools::document()
Updating absconc documentation
Loading absconc
Writing NAMESPACE
4) Load your package with devtools::load_all().
> devtools::load_all()
Loading absconc
5) Run your function.
> absconc(1,2,3)
Slope:2
Intercept:3
Concentration:5
The following example code in the documentation of the Thinknum package
install.packages("Thinknum")
library(Thinknum)
thinknumdata = Thinknum("total_revenue(goog)")
leads on my machine to the following error:
Error in Thinknum("total_revenue(goog)") : Requested Expression does not exist.
It would help me a lot, if one or more people could run the example code on another machine.