首页 > 解决方案 > devtools::document 尝试将目录作为文件打开

问题描述

我正在尝试使用devtools::document()为 R 包构建 man 文件。但是,当我document()从包裹内调用时,我得到以下信息:

Updating xpcaR documentation
Loading xpcaR
Error in file(con, "r") : cannot open the connection
Calls: suppressPackageStartupMessages ... roxy_tag_rd.roxy_tag_example -> read_lines -> <Anonymous> -> file
In addition: Warning messages:
1: In file(con, "r") :
  'raw = FALSE' but '/Users/andersonberg1/Documents/GitLab/xpcar/xpcaR/' is not a regular file
2: In file(con, "r") :
  cannot open file '/Users/andersonberg1/Documents/GitLab/xpcar/xpcaR/': it is a directory
Execution halted

Exited with status 1.

警告是完全正确的:.../xpcaR/是一个目录,而不是一个文件。实际上,它是我调用时所在的目录document()。为什么它试图将目录作为文件打开?

我目前的想法是,由于某种原因,它正在寻找一些文件名,然后是空的,所以当它出现时

full_filename = paste0(path2package, filename)

filename是 NULL 所以它最终只是一个包的路径。但是,我不知道为什么会这样。

标签: rdevtools

解决方案


我意识到问题在于我正在编写一个#' @example,但尚未填写该字段。简而言之

#' ...
#' @examples
#' @export
foo = function(){}

导致上述错误,但是

#' ...
#' @examples
#' print("Hello world")
#' @export
foo = function(){}

解决它。


推荐阅读