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
Related
I'm attempting to create a small test R package just to get a hang of the workflow. I've been following the tutorial found here: https://r-pkgs.org/index.html Everything has been running smoothly but eventually I want to add rcpp code to my package and this is where I'm running into problems. The function use_rcpp in the devtools package is supposed to set up your package with everything you need to start adding c++ files. However once the command is done running it tells you to copy and paste comments into a file that does not exist. The tutorial I'm following says the same thing here https://r-pkgs.org/src.html#cpp but just says to add the roxygen tags to your package. It doesn't specify where I need to add them.
The output I'm getting is different from the one in the tutorial but I assume thats just because im running a different version.
The output the function is giving:
✔ Setting active project to
'R/packages/rcppTester'
✔ Creating 'src/'
✔ Adding '.o', '.so', '*.dll' to 'src/.gitignore'
● Copy and paste the following lines into
'R/packages/rcppTester/R/rcppTester-package.R':
## usethis namespace: start
#' #useDynLib rcppTester, .registration = TRUE
## usethis namespace: end
NULL
[Copied to clipboard]
✔ Adding 'Rcpp' to LinkingTo field in DESCRIPTION
✔ Adding 'Rcpp' to Imports field in DESCRIPTION
● Copy and paste the following lines into
'R/packages/rcppTester/R/rcppTester-package.R':
## usethis namespace: start
#' #importFrom Rcpp sourceCpp
## usethis namespace: end
NULL
[Copied to clipboard]
Again I have no file named "rcppTester-package.R" and my package is throwing errors when I try and use the cpp files. Any advice would be greatly appreciated.
You do not have to use devtools or usethis if they confuse you -- they do add a layer of obfuscation that sometimes obstruct what is happening.
Rcpp itself has a function Rcpp.package.skeleton(), and the RStudio IDE has something related (but independent) under 'File -> New Project -> Package with Rcpp'. I use both. You could start with either and get a package that compiles. Both will do that.
Take that as a snapshot and then add roxygen2 documentation. If you do it manually, you need to run compileAttributes() to get the roxygen markup from the C++ file to the R file where roxygenize() will see it. RStudio does both for you automatically.
So to sum up: try separating 'package with Rcpp' and 'package using roxygen' if the joint 'package using Rcpp and roxygen' gives you issues.
I am unable to generate .Rd documentation files for my package using RStudio and Roxygen2. First, let me mention that I have gone through similar problems posted here and have already done the following:
Roxygen2 blocks initiated at the beginning of file with a #'
Configured Build Tools>Checked generate documentation with Roxygen> Configure > Checked all fields under 'Use roxygen to generate' and 'Automatically roxygenize when running'
Made sure there were no .Rd files in the 'man' folder
And even after that, when I perform a 'Build and Reload' on RStudio I get the following output (please note the line that reads: No man pages found in package MYPACKAGE:
=
=> devtools::document(roclets=c('rd', 'collate', 'namespace', 'vignette'))
>
Updating MYPACKAGE documentation
Loading MYPACKAGE
Documentation completed
==> Rcmd.exe INSTALL --no-multiarch --with-keep.source MYPACKAGE
installing to library C:/Users/user/Documents/R/win-library/3.3
installing source package 'MYPACKAGE' ...
** R
** data
* moving datasets to lazyload DB
** preparing package for lazy loading
No man pages found in package 'MYPACKAGE'
** help
* installing help indices
** building package indices
** testing if installed package can be loaded
DONE (MYPACKAGE)
Edit:
Upon further investigation, it appears that this was caused by the fact that I have sub-directories within my R directory, which is not supported by default. A possible solution was located here which, however, I haven't yet tried out. I will report back with the outcome as soon as I am able to perform the tests.
I had the same error. roxygen2 was creating correctly the md files in the /man directory but they were not found at compilation time. I had the following error.
No man pages found in package
After a bit of time I found that in one of the R file I had a source statement
source("C:/Users/vaulot/Google Drive/Scripts/R library/dv_function_pr2.R")
My guess is that there was some code in the source file interfering with roxygen2.
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.
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.
Building a package results in the following warning:
* checking for unstated dependencies in tests ... WARNING
‘library’ or ‘require’ call not declared from: ‘testthat’
* checking tests ...
Running ‘test-all.R’
OK
* checking PDF version of manual ... OK
WARNING: There was 1 warning.
The package directory has a folder called tests, with a file test-all.R:
library(testthat)
library(bootLR)
test_package("bootLR")
Then a subfolder testthat with two files in it that hold the various tests.
The error message is likely telling me that I have not declared testthat in the DESCRIPTION file, but I don't want to require its installation by end-users, and I believe that putting the library(testthat) statement in the test-all.R file comes from the testthat manual.
Any way around this, or do I have to add it in the proper way (that forces uses to install testthat)?
Edit: I guess adding it to Suggests: might be the best way to do this?
Maybe suggests? As per Hadley.