用 roxygen2 覆盖 NAMESPACE 和 Rd [英] Overwriting NAMESPACE and Rd with roxygen2

查看:70
本文介绍了用 roxygen2 覆盖 NAMESPACE 和 Rd的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 RStudio 创建了一个新包.在配置构建工具"中,我选中了使用 Roxygen 生成文档".

I create a new package with RStudio. In "Configure Build Tools", I check "Generate documentation with Roxygen".

我第一次单击构建"窗格中的文档"时,一切正常:

The first time I click on "Document" in the "Build" pane, everything works fine:

==> roxygen2::roxygenize('.', roclets=c('rd', 'collate', 'namespace'))

First time using roxygen2. Upgrading automatically...
Writing hello.Rd
Writing NAMESPACE
Documentation completed

我知道这个命名空间:

# Generated by roxygen2: do not edit by hand

export(hello)

和这个文件hello.Rd:

% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/hello.R
\name{hello}
\alias{hello}
\title{Hello}
\usage{
hello(x)
}
\arguments{
\item{x}{string}
}
\value{
a string
}

但是现在,我修改了文件hello.R,然后我遇到了两个问题.首先出现这个窗口:

But now, I modify the file hello.R, and then I get two problems. Firstly, this window appears:

如果我点击是",什么都不会发生.

If I click on "Yes", nothing happens.

其次,roxygen2 似乎无法覆盖 hello.Rd,因为我在构建"窗格中看到了此文本:

Secondly, it seems that roxygen2 cannot overwrite hello.Rd, because I get this text in the "Build" pane:

==> roxygen2::roxygenize('.', roclets=c('rd', 'collate', 'namespace'))

Error: The specified file is not readable: U:\Data\Rtests\testPackage\man/hello.Rd
Execution halted

Exited with status 1.

我发现更新文档的唯一方法是运行:

The only way I found to update the documentation is to run:

roxygen2::roxygenize(clean=TRUE)

此命令首先清除所有内容,NAMESPACE 和 Rd 文件,然后生成 NAMESPACE 和 Rd 文件.

This command firstly cleans everything, the NAMESPACE and the Rd files, and then generates the NAMESPACE and the Rd files.

不知道是不是Rtools路径的问题.我尝试通过以下方式设置路径:

I don't know whether this is an issue with the path of Rtools. I tried to set the path by doing:

Sys.setenv(PATH="%PATH%;C:/Program Files/Rtools/gcc-4.6.3/bin;C:/Program Files/Rtools/gcc-4.6.3/bin64;C:/Program Files/Rtools/gcc-4.6.3/i686-w64-mingw32/bin;C:/Program Files/Rtools/bin")

但这并不能解决问题.

我正在使用:

  • roxygen2 5.0.1

RStudio 0.99.892

RStudio 0.99.892

Windows 7

R 版本 3.3.1

推荐答案

问题原因.

roxygen2 包依赖于 digest 包.错误(指定的文件不可读)是由digest包的digest函数产生的,在这个函数调用file.access 函数:https://github.com/eddelbuettel/digest/blob/master/R/digest.R#L102.

Cause of the problem.

The roxygen2 package depends on the digest package. The error (The specified file is not readable) is generated by the digest function of the digest package, at the moment when this function calls the file.access function: https://github.com/eddelbuettel/digest/blob/master/R/digest.R#L102.

我明白了:

> file.access("U:/Data", 4)
U:/Data 
     -1 

这意味着U:/Data 没有读取权限.但事实并非如此:它具有读取权限.问题是我的 U: 驱动器是一个网络驱动器",并且网络驱动器的 file.access 函数存在一些问题,我们可以在这里看到示例:https://github.com/eddelbuettel/digest/issues/13.

That means that U:/Data has not the read permission. But this is not true: it has the read permission. The problem is that my U: drive is a "network drive", and there are some issues with the file.access function for network drives, as we can see here for example: https://github.com/eddelbuettel/digest/issues/13.

如果在 digest::digest 中使用 R.utils::fileAccess 而不是 file.access,问题将得到解决功能.

The problem would be solved if R.utils::fileAccess would be used instead of file.access in the digest::digest function.

所以,首先将digest::digest函数的代码修改如下.

So, firstly take the code of the digest::digest function and modify it as follows.

mydigest <- function (object, algo = c("md5", "sha1", "crc32", "sha256", 
    "sha512", "xxhash32", "xxhash64", "murmur32"), serialize = TRUE, 
    file = FALSE, length = Inf, skip = "auto", ascii = FALSE, 
    raw = FALSE, seed = 0, errormode = c("stop", "warn", "silent")) 
{
  file.access <- R.utils::fileAccess
  .... the code of the digest function here ...
}

然后做:

library(digest)
R.utils::reassignInPackage("digest", "digest", mydigest)

现在可以通过以下方式更新文档:

And now the documentation can be updated by doing:

roxygen2::roxygenize()

这篇关于用 roxygen2 覆盖 NAMESPACE 和 Rd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆