Title: | Run 'roxygen2' on (Chunks of) Single Code Files |
---|---|
Description: | Have you ever been tempted to create 'roxygen2'-style documentation comments for one of your functions that was not part of one of your packages (yet)? This is exactly what this package is about: running 'roxygen2' on (chunks of) a single code file. |
Authors: | Andreas Dominik Cullmann [aut, cre] |
Maintainer: | Andreas Dominik Cullmann <[email protected]> |
License: | BSD_2_clause + file LICENSE |
Version: | 4.0.0.9000 |
Built: | 2025-02-06 04:12:00 UTC |
Source: | https://gitlab.com/fvafrcu/document |
Have you ever been tempted to create roxygen2-style documentation
comments
for one of your functions that was not part of one of your packages (yet)?
This is exactly what this package is about: running
roxygen2::roxygenize
on (chunks of)
a single code file.
This package enables you to
create function documentation with roxygen2
detect code/documentation mismatches
save the documentation to disk
view the documentation in your interactive R session
You will probably be looking for document
and
man
, the remaining functions are mainly
for internal use.
R is a programming language that supports and checks documentation for
program libraries (called ‘packages’). The package roxygen2 provides a
tool for creating documentation from annotated source code - much like
doxygen
, javadoc
and docstrings/pydoc
do.
And R is a free software environment for statistical computing and graphics, used by people like me who start out hacking down code, eventually pouring chunks of code into functions (and sometimes even ending up creating and documenting packages). Along that work flow you cannot use R's documentation system, let alone roxygen2, unless you have come to forge your code into a package.
I am fully aware of the fact that roxygen2 is meant to document packages, not single code chunks. So should you. Nevertheless I feel the temptation to use roxygen2-style comments in code chunks that are not part of any package. And to convert them to pdf for better readability.
This package writes to disk, so never run as superuser.
This package is basically a wrapper to
roxygen2. It internally creates a temporary package from the
code file provided (using
utils::package.skeleton
)
which it then passes to
roxygen2::roxygenize
.
R CMD
commands run by callr.
docstring
(https://cran.r-project.org/package=docstring) also creates temporary
help pages as well but using a different technical approach (allowing you to
view them in the RStudio
help pane). But it creates them from python
style docstring
-like comments it then parses into roxygen2.
And it does not write to file so far.
Document (Chunks of) an R Code File
document( file_name, working_directory = NULL, output_directory = tempdir(), dependencies = NULL, sanitize_Rd = TRUE, runit = FALSE, check_package = TRUE, check_as_cran = check_package, stop_on_check_not_passing = check_package, clean = FALSE, debug = TRUE, ... )
document( file_name, working_directory = NULL, output_directory = tempdir(), dependencies = NULL, sanitize_Rd = TRUE, runit = FALSE, check_package = TRUE, check_as_cran = check_package, stop_on_check_not_passing = check_package, clean = FALSE, debug = TRUE, ... )
file_name |
The name of the R code file to be documented. |
working_directory |
A working directory. Keep the default. |
output_directory |
The directory to put the documentation into. You
might want to use |
dependencies |
A character vector of package names the functions depend on. |
sanitize_Rd |
Remove strange characters from |
runit |
Convert the text received from the help files if running RUnit? Do not bother, this is for Unit testing only. |
check_package |
Run |
check_as_cran |
Use the |
stop_on_check_not_passing |
Stop if |
clean |
Delete the working directory? |
debug |
For internal use only: Summarize errors for |
... |
Arguments passed to
|
A list containing
The path to the pdf file produced,
The path to the text file produced,
The path to the html file produced,
The return value of
rcmdcheck::rcmdcheck()
One of the main features of R CMD check
is checking for
code/documentation mismatches (it behaves pretty much like
doxygen
).
No build system can check whether your documentation is useful, but
R CMD check
checks if it is formally matching your code. This check is the basic
idea behind document. The possibility to disable the
R CMD check
is
there to disable CPU consuming checks while testing the package. Stick with
the default!
And do not forget to export your functions using the line
#' @export
should you provide examples.
res <- document(file_name = system.file("files", "minimal.R", package = "document"), check_package = FALSE) # this is for the sake of CRAN cpu # time only. _Always_ stick with the default! # View R CMD check results. If we had set check_package to TRUE in the above # example, we now could retrieve the check results via: cat(res[["check_result"]][["output"]][["stdout"]], sep = "\n") cat(res[["check_result"]][["output"]][["stderr"]], sep = "\n") # Copy docmentation to current working directory. # This writes to your disk, so it's disabled. # Remove or comment out the next line to enable. if (FALSE) file.copy(res[["pdf_path"]], getwd())
res <- document(file_name = system.file("files", "minimal.R", package = "document"), check_package = FALSE) # this is for the sake of CRAN cpu # time only. _Always_ stick with the default! # View R CMD check results. If we had set check_package to TRUE in the above # example, we now could retrieve the check results via: cat(res[["check_result"]][["output"]][["stdout"]], sep = "\n") cat(res[["check_result"]][["output"]][["stderr"]], sep = "\n") # Copy docmentation to current working directory. # This writes to your disk, so it's disabled. # Remove or comment out the next line to enable. if (FALSE) file.copy(res[["pdf_path"]], getwd())
Display a help
-like page from an existing R
documentation (*.Rd) file, a topic from a temporary package with
options("document_package_directory")
set or a topic from an R code
file containing roxygen2 documentation.
man(x, topic = NA, force_Rd = FALSE)
man(x, topic = NA, force_Rd = FALSE)
x |
One of the following: |
topic |
A |
force_Rd |
if |
Invisibly the status of display_Rd
.
document::document(file_name = system.file("files", "minimal.R", package = "document"), check_package = FALSE) document::man("foo") # this equivalent to path <- system.file("files", "minimal.R", package = "document") document::man(x = path, topic = "foo")
document::document(file_name = system.file("files", "minimal.R", package = "document"), check_package = FALSE) document::man("foo") # this equivalent to path <- system.file("files", "minimal.R", package = "document") document::man(x = path, topic = "foo")
Get a usage template for a function from within the function. If you encounter misguided usage, you can display the template.
usage(n = -1, usage = FALSE)
usage(n = -1, usage = FALSE)
n |
A negative integer giving the number of from to frames/environments
to go back (passed as |
usage |
Give this functions usage (as a usage example ...) and exit? |
A character string giving the Usage as help
would do.
# usage with assignment operator: foo <- function(x) { u <- usage() message("Usage is: ", u) } foo() # usage without assignment operator: bar <- function(x) { message(usage(n = -2)) } bar()
# usage with assignment operator: foo <- function(x) { u <- usage() message("Usage is: ", u) } foo() # usage without assignment operator: bar <- function(x) { message(usage(n = -2)) } bar()