And*_*ris 7 r devtools roxygen2 dplyr magrittr
尝试R使用roxygen2和构建我的第一个包devtools。我在该部分添加了一个使用%>%和的函数。当我运行它时失败,因为它找不到函数或.mutate@examplescheck()%>%mutate
我有#' importFrom magrittr %>%和#' importFrom dplyr mutate在函数的.R文件中。我也有magrittr和dplyr下Imports:的DESCRIPTION文件。运行后document(),我的NAMESPACE文件包含importFrom(dplyr,mutate)和importFrom(magrittr,"%>%").
最小R/test.R文件:
#' Conditional mutate
#'
#' \code{mutate_cond} mutates the \code{data.frame} only on the rows that
#' satisfy the condition.
#'
#' @param .data \code{data.frame}
#' @param condition expression with the condition to be evaluated
#' @param ... arguments passed to \code{mutate}
#' @param envir environment inherited from \code{parent.frame()}
#'
#' @return \code{data.frame}
#' @importFrom dplyr mutate
#' @importFrom magrittr %>%
#'
#' @examples
#' data(iris)
#' iris %>%
#' mutate(aux = 0) %>%
#' mutate_cond(Petal.Length > 1.3,aux = 3)
#'
#' @export
mutate_cond <- function(.data, condition, ..., envir = parent.frame()) {
condition <- eval(substitute(condition), .data, envir)
.data[condition, ] <- .data[condition, ] %>% mutate(...)
.data
}
Run Code Online (Sandbox Code Playgroud)
最小DESCRIPTION文件:
Package: test
Version: 0.1
Date: 2019-06-07
Title: Functions
Description: Some functions I use.
Author: me
Maintainer: me <myemail@email.com>
Encoding: UTF-8
License: GPL-3
Imports: dplyr, magrittr
Run Code Online (Sandbox Code Playgroud)
NAMESPACE生成document():
# Generated by roxygen2: do not edit by hand
export(mutate_cond)
importFrom(dplyr,mutate)
importFrom(magrittr,"%>%")
Run Code Online (Sandbox Code Playgroud)
我希望此示例代码能够成功运行并通过check(). 相反,我收到此错误消息:
? checking examples ... ERROR
Running examples in ‘test-Ex.R’ failed
The error most likely occurred in:
> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: mutate_cond
> ### Title: Conditional mutate
> ### Aliases: mutate_cond
>
> ### ** Examples
>
> data(iris)
> iris %>%
+ mutate(aux = 0) %>%
+ mutate_cond(Petal.Length > 1.3,aux = 3)
Error in iris %>% mutate(aux = 0) %>% mutate_cond(Petal.Length > 1.3, :
could not find function "%>%"
Execution halted
1 error ? | 0 warnings ? | 0 notes ?
Run Code Online (Sandbox Code Playgroud)
此外,如果我将require(dplyr)和添加require(magrittr)到该@examples部分,错误就会消失,或者如果我删除整个@examples部分,错误就会消失。
为什么这个包裹不会通过check()?
谢谢!
小智 0
添加
exportPattern("^[[:alpha:]]+")
Run Code Online (Sandbox Code Playgroud)
我的 NAMESPACE 文件解决了我这边的问题。
| 归档时间: |
|
| 查看次数: |
1194 次 |
| 最近记录: |