R Roxygen2 documentation without building a package - r

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!

Related

How can I wrap an interactive R learnr tutorial in a package?

I’m new to creating learnr tutorials and even more to creating packages, but after reading tutorials on these two topics, I can now create simple packages and simple learnr tutorials. Now that I know a bit about both topics, I would like to deploy my interactive tutorials in a basic package, but there are not many resources available. Can you show me how to do this in the simplest possible way?
You'll need to:
Create a package
Use a tutorial inside that package
1. Create a package
Check the chapter 2 of R Packages by Hadley Wickham. You'll understand how to start one by using:
library(devtools)
create_package("path/to/package")
2. Use a tutorial inside that package
Once you started a package you'll need to create a tutorial inside the inst directory of your package. use_tutorial() does it for you. Be sure to be in the package project inside RStudio.
usethis::use_tutorial(name, title)
That's all. Be sure to check the learnr documentation for more details. More steps in https://education.rstudio.com/blog/2020/09/delivering-learnr-tutorials-in-a-package/

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...

CRAN submission - How should I document hidden functions in 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?

Linking to documentation page without function in R using roxygen2

I am wondering if there is a possibility, during writing a package in R, to link to the documentation page in R that has no functions included but has only package-info?
For example \link[stats]{stats-package.R}?
One of the possibillities is \link[stats]{stats-package} without .R extansion (but it will link to stats-package page). If you just want to link the package use \pkg{package} e.g. \pkg{stats}. For more info try Writing R Extensions

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.

Resources