CRAN submission - How should I document hidden functions in R? - r

Long story short:
My aim is to submit a R package developed with roxygen2 to CRAN, and I need to find some guidelines on writing and documenting hidden functions.
More details:
I am writing my first R package using roxygen2 in Rstudio. I have documented all the functions I wrote so far, so that my collaborators can easily understand their purpose before going into the details of the script. All the functions that are of no use to the user, but necessary to the package, are not exported in the namespace and eliminated from the package manual/index (#keywords internal). At the same time, my collaborators can still read their documentation using the help of Rstudio.
Eventually, I would like to remove the documentation of these "hidden functions" from the help because there is no reason to keep it. I was considering to follow a suggestion I found in other posts, that is changing #' with ## in the documentation created with roxygen2. However, I am not sure this is the correct procedure to implement, and if removing the documentation of a function in the help and the manual is compatible with CRAN requirements.
Can anyone point me to some guidelines related to this issue, or has any experience to share?

Related

R Roxygen2 documentation without building a package

I am currently programming within an R project. Right now there is no need for building a whole package, but I would like to use roxygen to create documentation of several functions nonetheless.
Whenever I am looking for "object documentation" or "roxygen", the context is immediately package development (e.g. https://r-pkgs.org/man.html).
Is it possible to document the functions using roxygen without building a package?
Thanks a lot!

add and Rcpp file to an existing r Package?

I have already made a simple R package (pure R) to solve a problem with brute force then I tried to faster the code by writing the Rcpp script. I wrote a script to compare the running time with the "bench" library. now, how can I add this script to my package? I tried to add
#'#importFrom Rcpp cppFunction
on top of my R script and inserting the Rcpp file in the scr folder but didn't work. Is there a way to add it to my r package without creating the package from scratch? sorry if it has already been asked but I am new to all this and completely lost.
That conversion is actually (still) surprisingly difficult (in the sense of requiring more than just one file). It is easy to overlook details. Let me walk you through why.
Let us assume for a second that you started a working package using the R package package.skeleton(). That is the simplest and most general case. The package will work (yet have warning, see my pkgKitten package for a wrapper than cleans up, and a dozen other package helping functions and packages on CRAN). Note in particular that I have said nothing about roxygen2 which at this point is a just an added complication so let's focus on just .Rd files.
You can now contrast your simplest package with one built by and for Rcpp, namely by using Rcpp.package.skeleton(). You will see at least these differences in
DESCRIPTION for LinkingTo: and Imports
NAMESPACE for importFrom as well as the useDynLib line
a new src directory and a possible need for src/Makevars
All of which make it easier to (basically) start a new package via Rcpp.package.skeleton() and copy your existing package code into that package. We simply do not have a conversion helper. I still do the "manual conversion" you tried every now and then, and even I need a try or two and I have seen all the error messages a few times over...
So even if you don't want to "copy everything over" I think the simplest way is to
create two packages with and without Rcpp
do a recursive diff
ensure the difference is applied in your original package.
PS And remember that when you use roxygen2 and have documentation in the src/ directory to always first run Rcpp::compileAttributes() before running roxygen2::roxygenize(). RStudio and other helpers do that for you but it is still easy to forget...

Using another R package function without using the whole package as dependency

I'm working on an R package here and got this doubt: I need an auxiliar function from another package, but I don't want to include the entire package as a dependency because I only need this one function. What is the correct procedure here? Is it OK if both codes are GPL-2 and I just copy/paste the function to my package? Should I contact the author? Or is it best to include the whole package as a dependency?
If it's just a small function, I don't see a problem with copying the code into your own package (since everything is GPLed). You should acknowledge the source in your package though.
This has the benefit of insulating your code from any changes in the other package; it's not unusual for updates to packages to break other packages downstream. It has the downside that if those updates were useful (bug fixes or added functionality) then you don't benefit from them either.

How to use package `RcppExamples`?

I'm new to Rcpp and want to export some C++ class into R. I've install RcppExmples intending to learn some code snippet. But I didn't even know how to use it? help(RcppExamples) only to get:
Description:
This package shows some simple examples for the use of ‘Rcpp’.
Both the older ('classic') and new API are documented.
It can also serve as a working template to create packages that
use ‘Rcpp’ to interface C++ code or libraries.
Where can I get the examples?
The sources for the examples in the package are, well, in the package itself.
This is Rcpp. It works with C++ source code, and R code. You don't use this like a normal package, you create packages with it. From source.
Did you had a look at the manual? I think it's clear from this document. But the DESCRIPTION file says:
Note that the documentation in this package currently does not cover all the features in the package. It is not even close.
So I fear that's all you can get - besides looking at the source code.

Can Roxygen ignore non-user functions?

I've just started playing around with the roxygen package and I've very happy with the results so far. However I was wondering, is there a way to specify to roxygen that it should ignore certain functions that are not user-accessible?
Specifically, I'd rather not have a .Rd file pop up because I'm using the .onLoad() hook in my package. This function is already documented in the base package so there's no reason for me to re-document it.
Well, I finally found and browsed the Roxygen-devel list at R-forge to see when this would be implemented, and it appears to already be in the version of Roxygen that is on CRAN. The key is to specify use.Rd2=TRUE when calling roxygenize(). Under this mode, Roxygen will skip creating documentation for any functions that are not preceded by Roxygen comments.
This is on their to do list - in the next version, only functions with roxygen documentation will create man files.
Use the internal keyword field (i.e. #keywords internal) to remove the function from the documentation and make it available for experienced users only.
Source: roxygen2 vignette.

Resources