I'm writing an R package and I need it run a short bit of code before the user dives in. Specifically, this is my .onAttach():
#' #importFrom httr GET
.onAttach <- function(libname, pkgname) {
url <- "http://news.bbc.co.uk"
sink <- GET(url)
}
httr is listed under the Imports part of my DESCRIPTION file.
My problem is that when I run R CMD check I get the following error:
Error : .onAttach failed in attachNamespace() for 'scholar', details:
call: default_ua()
error: could not find function "packageVersion"
Error: package or namespace load failed for 'scholar'
Since packageVersion() is in utils, which I'm guessing isn't available at this stage in the package loading process, I can "solve" this by adding library(utils) in the first line of .onAttach() but then I get this NOTE:
* checking dependencies in R code ... NOTE
'library' or 'require' call to 'utils' in package code.
Please use :: or requireNamespace() instead.
See section 'Suggested packages' in the 'Writing R Extensions' manual.
I've tried replacing the library call with requireNamespace("utils") but that's not helping either.
I'd be grateful for any advice on how to fix this; my own searches aren't turning up anything useful.
Related
I have a package which does nothing but reexport other packages' functions.*
However, one of these functions is DBI::dbBegin:
#' #importFrom DBI dbBegin
#' #export
DBI::dbBegin
If I then use roxygen to build the documentation, it works just fine.
==> devtools::document(roclets = c('rd', 'collate', 'namespace'))
Updating foo documentation
Writing NAMESPACE
Loading foo
Writing reexports.Rd
Writing NAMESPACE
Documentation completed
However, when I build the package, a warning is thrown:
==> Rcmd.exe INSTALL --no-multiarch --with-keep.source foo
[...]
*** installing help indices
converting help for package 'foo'
reexports html
Rd warning: C:/Users/xxx/Documents/foo/man/reexports.Rd:14: file link 'dbBegin' in package 'DBI' does not exist and so has been treated as a topic
[...]
The problem here is that DBI::dbBegin's man page is actually called transactions.Rd (along with other functions).
The build itself is successful, and even using the documentation itself works: ?foo::dbBegin opens the standard "Objects exported from other packages" page which successfully links to the correct man page.
So, as far as I can tell, the warning seems harmless, but is there anything I can declare using roxygen to point it to the correct man page?
* That's a lie
I have created and downloaded an R package using roxygen2 development tools. When I update the source code R files, the documentation updates fine, but the function code itself does not. How do I get the function code to update when I reinstall the package with install.packages("package-name")?
I have tried inserting error messages at the beginning of every function using stop("..."). When I reinstall the code, the functions do not output an error message as they should but work as they did before I updated the code.
Each time I update the code, I use the following commands:
devtools::document()
devtools::install()
install.packages("package-name", repos=NULL, type="source")
library(package-name)
Just for further information, when I try to install the package this way:
install.packages("package-name")
I get the following error message:
Warning in install.packages :
package ‘package-name’ is not available (for R version 3.6.0)
I got this same error message when my R version was 3.6.0, and even now after updating to 3.6.1
I have not uploaded the package to any repositories, so I figured this makes sense, and instead install it locally from my package files with repos=NULL.
#' Roxygen comments - this part updates
#'
#' etc.
functionName <- function(...) {
stop("...")
...
# This function should crash with an error message every time it is called,
# but instead the function body is never updated.
}
Upon reinstalling the package, I expect the output of my functions to be an error message, but instead, they output the same result as they did before I updated the package.
Documentation updates, function bodies do not.
So it turns out I found an answer to my own question...
The problem was with a warning message I was getting:
Warning message:
In body(fun) : argument is not a function
Despite not ever using body(), this function was getting called internally somewhere, and the warning prevented the code from being updated (but the documentation still updates, for some reason).
Clearing my global environment with rm(list=ls()) cleared my error.
I'm writing an R package with the help of devtools.
I have a R function which uses Fortran subroutines (called with .Fortran() function) from a packagename.so file located in the src folder.
I put #useDynLib packagename in R/packagename.R and ran devtools::document() to add useDynLib(packagename) to NAMESPACE but when I run devtools::check() an error occures.
I read the R packages documentation and googled the question but I haven't found a solution yet.
Two related questions come to my mind:
do I need the Fortran source code and let R compile it?
should the shared object have the same name of the package or not?
TL;DR
How do I get rid of the following error after running devtools::check()?
Error: package or namespace load failed for ‘ROCkerMeth’ in library.dynam(lib, package, package.lib):
shared object ‘ROCkerMeth.so’ not found
I'm using setRefClass to create classes and since is part of the methods package, I presumed you need to declare this dependency as an import.
However, the following minimal example fails Rcmd.exe check when importing methods:
#' #docType package
#' #import methods
A <- setRefClass("A")
with the following error (my package is called Test):
==> Rcmd.exe check Test_1.0.tar.gz
<Lots of checks here...>
* checking package dependencies ... ERROR
Namespace dependency not required: 'methods'
See the information on DESCRIPTION files in the chapter 'Creating R
packages' of the 'Writing R Extensions' manual.
Exited with status 1.
So from what I can make out, it appears I'm being told to remove the import for methods and so keep hidden the package's dependency on methods. Is my interpretation correct and if so, why hide the dependency on methods?
My setup:
Roxygen2 3.0.0
R: 3.0.2 (Frisbee Sailing)
IDE: RStudio 0.98.490
OS: Windows 8.1
After more hunting around, I realised that in my haste I forgot to add Imports: methods to my DESCRIPTION file.
I have got betaversion from website. The only available is windows installation as mybetapackage.zip file. When I installed the package, it does not work when I load it.
> utils:::menuInstallLocal()
> require(mypackage)
Loading required package: mypackage
Failed with error: ‘package ‘mypackage’ does not have a NAMESPACE and should be re-installed’
Is it possible to use this beta package someway ?
Edits:
I tried the following instructions to create own namespace. Namespace file contains the following:
exportPattern("^[^\\.]")
Now I am getting following warning.
Warning message:
In readLines(file) :
incomplete final line found on 'C:/Users/user/Documents/R/win-library/2.14/RCropStat/NAMESPACE
Based on the discussion above I am answering my own questions. All credit goes to who discussed this issue.
Create a file with the following text and put an extra line to avoid an error. Same in the directory for the package where you have description file.
exportPattern("^[^\\.]")