globalVariables() function generates Missing name - global-variables

I've got a package at https://github.com/histmr/Rekishi that generates the "no visible binding for global variable" on CMD check because I use a .Rda file to include data. I've tried adding
if(getRversion() >= "2.15.1") utils::globalVariables(c("kanji_conversion_table"))
to the Normalize.R file but that generates a different error
> document()
Updating Rekishi documentation
Loading Rekishi
Writing NAMESPACE
Warning: Normalize.R:13: Missing name
Deleting normalize_kanji.Rd
What am I doing wrong? Where do I add the globalVariables command?

Related

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")

SparkR reading and writing dataframe issue

I have a Spark DataFrame which I want to write to my disc, I used the following code-
write.df(data_frame,"dataframe_temp.csv",source="csv",mode="overwrite",schema="true",header="true")
It got completed and I can see a new folder created with a _SUCCESS file in it.
Now when I am trying to read from the same file, using following code-
dataframe2<-read.df("dataframe_temp.csv",inferSchema="true",header="true")
I am getting following error:
ERROR RBackendHandler: loadDF on org.apache.spark.sql.api.r.SQLUtils
failed Error in invokeJava(isStatic = TRUE, className, methodName,
...) : org.apache.spark.sql.AnalysisException: Unable to infer
schema for ParquetFormat at dataframe.csv. It must be specified
manually;
I have even tried using repartition
data_frame<-repartition(data_frame,1)
Any help?
You also have to specify the source as "csv":
dataframe2<-read.df("dataframe_temp.csv", source="csv")
Regarding the header argument:
Currently there is also a bug in SparkR for Spark 2.0, where the variable arguments of the write.df function aren't passed to the options parameter (see https://issues.apache.org/jira/browse/SPARK-17442). That's why the header is not written to the csv even if you specify header="true" on write.df.
Got it solved using parquet file format, parquet file format stores the schema by default.

undefined function / function not found

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

Load data "namespace not available"

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.

Correctly set R default graphic device to quartz?

I tried to add the following line in my .Rprofile file:
options(device = quartz)
It produced an error:
Error in options(device = quartz) : object 'quartz' not found
Then I tried:
options(device = "quartz")
And it works.
However, both work in the regular R session. Can anyone tell me what is the reason for the difference in behavior?
The erro message says it all. There is no data-object named 'quartz' and the options function is not expecting (nor can it find) a function name as an argument value for the 'device'-node.
You are seeing the effect of the environment where .Rprofile is being evaluated because some of the usual packages (such as stats or graphics) are not yet loaded. Read more about this at ?Startup. You could avoid this by starting .Rprofile with require(grDevices)

Resources