How to eliminate Roxygen warning about "No name found..."? - r

I'm calling roxygenize() with parameter use.Rd2 = TRUE. I have a file testcase.R where I create a simple S3 object using R.oo. Here's the contents of the file. There's nothing for roxygen to do here, and it should ignore the contents:
library( R.oo )
setConstructorS3( "TestCase" ,
function()
{
extend( Object() , "TestCase",
.parameters = list() ,
.validationData = list()
)
} )
And here's the error:
Error in parse.name(partitum) :
(converted from warning) No name found for the following expression in E:/mypackage/R/te
stcase.R line 1:
`library( R.oo ) . . .'
Calls: roxygenize ... <Anonymous> -> maybe.call -> do.call -> <Anonymous> -> par
se.name
How can I eliminate the warning? Per suggestions in other posts, I added the following as the first line, but it didn't work:
#' #nord

Upgrading to Roxygen2 eliminated the error.

Related

R CMD check Warning: "Undefined global functions or variables"

I am hopeful I can get advise on proper R packaging techniques. When I run R CMD check packagename I get these messages in reference to my zzz.R file:
File ‘packagename/R/zzz.R’:
.onLoad calls:
packageStartupMessage("my message.")
packageStartupMessage("another message.")
packageStartupMessage("and another message)
See section ‘Good practice’ in '?.onAttach'.
.onLoad: no visible global function definition for ‘unzip’
.onLoad: no visible global function definition for ‘file.move’
Undefined global functions or variables:
file.move unzip
Consider adding
importFrom("utils", "unzip")
to your NAMESPACE file.
I'm not entirely clear on what this means.
Per the first message, See section ‘Good practice’ in '?.onAttach'. I don't have an .onAttach() function. I just have an .onLoad() function. My package works fine without .onAttach(), so I am not sure what is being implied here.
I am not sure why I am shown .onLoad: no visible global function definition for ‘unzip’ and .onLoad: no visible global function definition for ‘file.move’ because I use unzip and file.move like this: utils::unzip(), ff::file.move().
How would I add importFrom("utils", "unzip") to my NAMESPACE file? I have not firsthand edited this file because when I open it I get a warning not to edit it by hand.
This is what my zzz.R file looks like:
.onLoad <- function(libname, pkgname) {
quiet <- function(x) {
sink(tempfile())
on.exit(sink())
invisible(force(x))
}
path <- paste0(.libPaths(), "/packagename/")[1]
if(file.exists(paste0(path, "data/"))) { invisible()
} else {
url <- "urlpath"
fname <- paste0(path, "data.zip")
packageStartupMessage("message.")
tryCatch({
utils::download.file(url, fname, mode = "wb")
zip_file <- paste0(path, "data.zip")
utils::unzip(zip_file, exdir = paste0(path, "uncompressed_data"))
from <- paste0(path, "uncompressed_data/data/")
to <- paste0(path, "data/")
quiet(ff::file.move(from, to))
quiet(file.remove(paste0(path, "data.zip")))
quiet(file.remove(paste0(path, "uncompressed_data"))) },
warning = function(cond) {
packageStartupMessage("message.")
packageStartupMessage("message") } )
}
}
My NAMESPACE file just says this:
# Generated by roxygen2: do not edit by hand
Thanks so much for your input.

Define active binding in a package when the active binding fails by default

Based on this Q&A , this code defines a package containing an active binding to the value 1. It passes devtools::check():
my_function <- function() 1
#' return 1
#' #usage my_active_binding
#' #name my_active_binding
NULL
.onLoad <- function(libname, pkgname) {
ns <- asNamespace(pkgname)
makeActiveBinding("my_active_binding", my_function, env = ns)
namespaceExport(ns, "my_active_binding")
}
However if my active binding fails by default (in my use case it should be used in a specific context),
then devtools::check() is not happy anymore.
Edit: actually if I use print() or message() rather than stop() I run into the same issues
my_function <- function() stop("stop!!!")
#' stop!!!
#' #usage my_active_binding
#' #name my_active_binding
NULL
.onLoad <- function(libname, pkgname) {
ns <- asNamespace(pkgname)
makeActiveBinding("my_active_binding", my_function, env = ns)
namespaceExport(ns, "my_active_binding")
}
See below :
-- R CMD check results ---------------------------------- abtest 0.0.0.9000 ----
Duration: 21s
> checking DESCRIPTION meta-information ... WARNING
Non-standard license specification:
GPL3
Standardizable: FALSE
> checking S3 generic/method consistency ... WARNING
Error in (function () : stop!!!
Calls: <Anonymous> -> Filter -> unlist -> lapply -> FUN -> <Anonymous>
Ex�cution arr�t�e
See section 'Generic functions and methods' in the 'Writing R
Extensions' manual.
> checking for code/documentation mismatches ... WARNING
Error in (function () : stop!!!
Calls: <Anonymous> ... Filter -> unlist -> lapply -> FUN -> get -> <Anonymous>
Ex�cution arr�t�e
> checking dependencies in R code ... NOTE
Error in (function () : stop!!!
Ex�cution arr�t�e
> checking foreign function calls ... NOTE
Error in (function () : stop!!!
Calls: <Anonymous> -> lapply -> FUN -> get -> <Anonymous>
Ex�cution arr�t�e
See chapter 'System and foreign language interfaces' in the 'Writing R
Extensions' manual.
> checking R code for possible problems ... NOTE
Error in (function () : stop!!!
Calls: <Anonymous> ... withCallingHandlers -> do.call -> <Anonymous> -> get -> <Anonymous>
Ex�cution arr�t�e
> checking Rd \usage sections ... NOTE
Error in (function () : stop!!!
Calls: <Anonymous> ... Filter -> unlist -> lapply -> FUN -> get -> <Anonymous>
Ex�cution arr�t�e
The \usage entries for S3 methods should use the \method markup and not
their full name.
See chapter 'Writing R documentation files' in the 'Writing R
Extensions' manual.
0 errors v | 3 warnings x | 4 notes x
Erreur : R CMD check found WARNINGs
Ex�cution arr�t�e
Exited with status 1.
How can I do to integrate this active binding in my package and satisfy devtools::check() / R CMD check ?

Rcpp code throwing error when knitting in Rstudio

Im trying to run the following rmarkdown code:
https://docs.google.com/document/d/164VZx3_cZ4tBa1Um39VH1cQ4zqRuCvpCTj-B50Vq2gk/edit?usp=sharing
But Im getting the following error when I knit the code:
Quitting from lines 26-47 (demo.Rmd)
Error in (function (file = "", code = NULL, env = globalenv(), embeddedR = TRUE, :
Error 1 occurred building shared library.
Calls: <Anonymous> ... block_exec -> in_dir -> engine -> do.call -> <Anonymous>
In addition: Warning message:
No function return type found for Rcpp::export attribute at file1af863722d6.cpp:4
Execution halted `
When I replace {Rcpp} with {rcpp} I get to run it but its not giving the output. How do I get it to run and give the output?

R namespace problems with 'logging' package

I'm writing an R package that uses the logging package from CRAN. In my code, I initialize logging when my package is loaded:
#' #importFrom logging basicConfig
.onAttach <- function(libname, pkgname) {
logging::basicConfig()
}
#' #importFrom logging setLevel
#' #export
setLogLevel <- function(level) {
setLevel(level)
}
And in my DESCRIPTION file I declare the dependency:
Depends:
R (>= 3.0.2),
Rcpp (>= 0.11.2)
Imports:
FNN,
plyr,
geosphere,
logging
However, it looks like R CMD check (which I invoke via "Check Package" in RStudio) doesn't like something about the namespaces:
* checking whether the package can be loaded with stated dependencies ... WARNING
Loading required package: Rcpp
Error : .onAttach failed in attachNamespace() for ‘ABC’, details:
call: UseMethod("updateOptions")
error: no applicable method for ‘updateOptions’ applied to an object of class "Logger"
Error: package or namespace load failed for ‘ABC’
Execution halted
It looks like this package (or one of its dependent packages) has an
unstated dependence on a standard package. All dependencies must be
declared in DESCRIPTION.
See the information on DESCRIPTION files in the chapter ‘Creating R
packages’ of the ‘Writing R Extensions’ manual.
...
* checking for missing documentation entries ... ERROR
Error: package or namespace load failed for ‘ABC’
Call sequence:
2: stop(gettextf("package or namespace load failed for %s", sQuote(package)),
call. = FALSE, domain = NA)
1: library(package, lib.loc = lib.loc, character.only = TRUE, verbose = FALSE)
Execution halted
Exited with status 1.
The updateOptions() method it's complaining about is part of the logging::basicConfig() function I call in my initialization:
> logging::basicConfig
function (level = 20)
{
rootLogger <- getLogger()
updateOptions(rootLogger, level = namedLevel(level))
rootLogger$addHandler("basic.stdout", writeToConsole, level = namedLevel(level))
invisible()
}
<environment: namespace:logging>
d> logging::updateOptions
function (container, ...)
UseMethod("updateOptions")
<environment: namespace:logging>
Thanks for any insight anyone can provide.

Building R package with Reference objects fails

I recently rewrote a package to use the new(er) R reference class objects. I've exported the three classes using export() in the NAMESPACE file so as far as I'm aware that should work. However when I test build the package I get an error at lazy loading stage:
** preparing package for lazy loading
Error in file(con, "rb") : invalid 'description' argument
ERROR: lazy loading failed for package ‘PACKAGE_NAME_HERE’
* removing ‘/Library/Frameworks/R.framework/Versions/3.0/Resources/library/PACKAGE_NAME_HERE’
I'm not sure what the problem is here. I don't know if it's relevant but the reference classes do store data on files in the tmp directory by having some fields set as accessor functions - I don't know if that's what s being complained about here when it says (con, "rb") which I guess is some connection thing. Does anybody have any ideas or advice for making sure reference classes get exported properly? My namespace is currently simple -
export(Main)
export(Mainseq)
export(Maintriplet)
Which are the three reference classes I exported by using #export tags in roxygen2.
What is it I'm doing (or not doing) that is throwing the lazy load error?
(ASIDE - I have no compiled code - all R, although the reference class methods do call some internal functions that are not exported, but these are supposed to be internal so I don't think I need to export them.
Thanks,
Ben.
EDIT:
My description file is as follows:
Package: HybRIDS
Type: Package
Title: Quick detection and dating of Recombinant Regions in DNA sequence data.
Version: 1.0
Date: 2013-03-13
Author: Ben J. Ward
Maintainer: Ben J. Ward <b.ward#uea.ac.uk>
Description: A simple R package for the quick detection and dating of Recombinant Regions in DNA sequence data.
License: GPL-2
Depends: ggplot2,grid,gridExtra,png,ape
I can't see what is wrong with this - the Depends are correct.
EDIT:
I've eliminated the first error with the description but I'm still getting the con error.
I think it's because the Mainseq class (which is nested in class Main) has some fields:
FullSequenceFile = "character",
FullSequence = function( value ) {
if( missing( value ) ){
as.character( read.dna( file = FullSequenceFile, format = "fasta", as.matrix = TRUE ) )
} else {
write.dna( value, file = FullSequenceFile, format = "fasta" )
}
},
InformativeSequenceFile = "character",
InformativeSequence = function( value ) {
if( missing( value ) ){
as.character( read.dna( file = InformativeSequenceFile, format = "fasta", as.matrix = TRUE ) )
} else {
write.dna( value, file = InformativeSequenceFile, format = "fasta" )
}
}
The idea being upon initialisation, the two character fields are filled with a path to a temp file in tmpdir, and when the variables are called or edited the files containing the variable data are read or written to. However it seems the variables are being accessed before this path is available because up package build the following happens:
** preparing package for lazy loading
Warning in file(con, "rb") :
cannot open file '/var/folders/kp/clkqvqn9739ffw2755zjwy74_skf_z/T//RtmpLB8ESC/FullSequenceaba52ac591f3': No such file or directory
Error in file(con, "rb") : cannot open the connection

Resources