I have some functions in a script that I would like to document those functions using #roxygen2, but the online resources have seen point towards documenting functions in a package. I do not want to create a package but just document my custom function as I go along. any resources would be of help.
I have written up some details about the function using #roxygen2 syntax and tried to document it but it returns an "Error: package.dir
must include a DESCRIPTION file" and,
"Did you call roxygenize()
in a directory that is not the package root?"
Here are #roxygen2 notes
#'@title get_weather.
#'@description The function takes arguments of directory, country, station and year.
#'@param directory The directory where the weather data is stored relative to the working.
#'@param country The country where the data was recorded
#'@param station The weather station number.
#'@param year The year in which the data was recorded.
#'@return A data frame called WDATA. it contains data on vapour pressure(VP), wind speed (WN), precipitation (RAIN), daily total radiation (DTR) and daily average temperature (DAVTMP).
Here is the function I want to document
get_weather <-
function(directory="..\\weather\\",country="NLD",station="1",year="954"){
weather <-
matrix(data=as.numeric(unlist(scan(paste(directory,country,
station,".",year,sep=""), what=list("","","","","","","","",""),
comment.char='*',fill=TRUE,quiet=TRUE))),ncol=9)
RDD = as.vector(weather[-1,4])
TMMN = as.vector(weather[-1,5])
TMMX = as.vector(weather[-1,6])
WDATA <- data.frame(
VP = as.vector(weather[-1,7]),
WN = as.vector(weather[-1,8]),
RAIN = as.vector(weather[-1,9]),
DTR = RDD / 1e+03,
DAVTMP = 0.5 * (TMMN + TMMX)
)
}
You could do what you'd like with the help of the docstring package https://cran.r-project.org/package=docstring
It allows you to add roxygen style documentation within a function and view that documentation using the typical help file viewer all without needing to convert your code into a full package.
The vignette provides a good introduction to how to use the package https://cran.r-project.org/web/packages/docstring/vignettes/docstring_intro.html
Note: I am the author of the package so this is a bit of self promotion but it seems to be incredibly relevant to the question asked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With