r - Documenting functions in an r script
问题描述
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)
)
}
解决方案
你可以在文档字符串包https://cran.r-project.org/package=docstring的帮助下做你想做的事
它允许您在函数中添加 roxygen 样式文档,并使用典型的帮助文件查看器查看该文档,而无需将您的代码转换为完整的包。
小插图很好地介绍了如何使用包https://cran.r-project.org/web/packages/docstring/vignettes/docstring_intro.html
注意:我是该软件包的作者,所以这有点自我推销,但它似乎与所提出的问题非常相关。
推荐阅读
- microcontroller - 为什么 XOR 指令会导致 C 标志设置为 1?
- angular - 页面源数据未设置为 ng2-smart-table 中的第一条记录。
- javascript - 单击按钮时折叠的导航栏未关闭
- java - 警告:编码密码看起来不像 BCrypt
- laravel - BadMethodCallException,方法 getLogin 不存在 l
- ios - 检查我是否有观察者在 firebase swift 中监听
- linux - “lorder”solaris 命令的 linux 等效项是什么?
- latex - 试图了解 Pandoc 如何从 Markdown 转换为 Latex
- php - 会话数据不会显示
- java - 如何在 Hibernate Criteria API 中添加 SQL-Server 查询提示