使用“foreach”包函数进行 R CMD 检查 --as-cran 时出现命名空间错误

问题描述 投票:0回答:1

因此,我尝试对要上传到 CRAN 的包运行 CMD 检查,但在 Windows 11 cmd 上运行它时,出现以下错误:

* using log directory 'C:/Users/Zick/Documents/YEAB/YEAB-master/YEAB.Rcheck'
* using R version 4.3.3 (2024-02-29 ucrt)
* using platform: x86_64-w64-mingw32 (64-bit)
* R was compiled by
    gcc.exe (GCC) 12.3.0
    GNU Fortran (GCC) 12.3.0
* running under: Windows 11 x64 (build 22631)
* using session charset: UTF-8
* using option '--as-cran'
* checking for file 'YEAB/DESCRIPTION' ... OK
* this is package 'YEAB' version '0.1.0'
* package encoding: UTF-8
* checking CRAN incoming feasibility ... WARNING
Maintainer: 'Emmanuel Alcala <[email protected]>'

New submission

Non-FOSS package license (CC-BY-4.0 + file LICENSE)

Unknown, possibly misspelled, fields in DESCRIPTION:
  'Extdata'

Strong dependencies not in mainstream repositories:
  rethinking

The Date field is over a month old.
* checking package namespace information ... OK
* checking package dependencies ... OK
* checking if this is a source package ... OK
* checking if there is a namespace ... OK
* checking for executable files ... OK
* checking for hidden files and directories ... OK
* checking for portable file names ... OK
* checking serialization versions ... OK
* checking whether package 'YEAB' can be installed ... ERROR
Installation failed.
See 'C:/Users/Zick/Documents/YEAB/YEAB-master/YEAB.Rcheck/00install.out' for details.
* DONE

Status: 1 ERROR, 1 WARNING
See
  'C:/Users/Zick/Documents/YEAB/YEAB-master/YEAB.Rcheck/00check.log'
for details.

当我打开“00install.out”文件时,我收到此错误:

* installing *source* package 'YEAB' ...
** using staged installation
** R
** data
** inst
** byte-compile and prepare package for lazy loading
Error : 'library' is not an exported object from 'namespace:foreach'
Error: unable to load R code in package 'YEAB'
Execution halted
ERROR: lazy loading failed for package 'YEAB'
* removing 'C:/Users/Zick/Documents/YEAB/YEAB-master/YEAB.Rcheck/YEAB'

问题是我没有从“foreach”命名空间导入任何名为“library”的函数。更重要的是,如果我没记错的话,“library”函数来自“base”包,所以我不明白为什么会出现这个错误。我的命名空间文件如下所示:

export(KL_div)
export(ab_range_normalization)
export(addalpha)
export(balci2010)
export(berm)
export(biexponential)
export(box_dot_plot)
export(bp_km)
export(bp_opt)
export(ceiling_multiple)
export(curv_index_fry)
export(curv_index_int)
export(den_histogram)
export(entropy_kde2d)
export(eq_hyp)
export(event_extractor)
export(exhaustive_lhl)
export(exhaustive_sbp)
export(exp_fit)
export(f_table)
export(fleshler_hoffman)
export(fwhm)
export(gaussian_fit)
export(gell_like)
export(get_bins)
export(hist_over)
export(hyperbolic_fit)
export(ind_trials_opt)
export(mut_info_discret)
export(mut_info_knn)
export(n_between_intervals)
export(objective_bp)
export(read_med)
export(sample_from_density)
export(trapezoid_auc)
export(unity_normalization)
export(val_in_interval)
importFrom(foreach,"%dopar%")
importFrom(foreach,foreach)
importFrom(MASS,kde2d)
importFrom(Polychrome,createPalette)
importFrom(cluster, clusGap)
importFrom(dplyr,between)
importFrom(dplyr,lag)
importFrom(infotheo,discretize)
importFrom(infotheo,mutinformation)
importFrom(magrittr,"%>%")
importFrom(minpack.lm,nls.lm)
importFrom(rmi,knn_mi)
importFrom(scales,show_col)
importFrom(sfsmisc,integrate.xy)
importFrom(zoo,rollapply)
importFrom(ggplot2, ggplot, aes, geom_point)
importFrom(grid, unit)
importFrom(gridExtra, grid.arrange)
importFrom(rethinking, HPDI)
importFrom(stats, median, optim, coef, fitted, approx, integrate, quantile)
importFrom("grDevices", "col2rgb", "grey", "rgb")
importFrom("graphics", "abline", "arrows", "axis", "box", "boxplot",
             "grid", "hist", "layout", "lines", "mtext", "par",
             "polygon", "stripchart", "text")
importFrom("stats", "approx", "bw.SJ", "coef", "cor", "density",
             "fitted", "integrate", "lm", "loess", "median", "na.omit",
             "nls", "nls.control", "optim", "pnorm", "quantile",
             "rbinom", "runif")
importFrom("utils", "read.table", "stack", "tail", "write.csv")
importFrom(grid, unit, gpar, grid.polygon, grid.text, grid.layout, grid.newpage, pushViewport, viewport, grid.rect, grid.points, grid.xaxis, grid.yaxis, grid.segments)
importFrom(minpack.lm, "nls.lm.control")
importFrom(utils, "stack", "write.csv")
importFrom(ggplot2, theme_gray, element_line, element_blank, element_text)
importFrom(cluster, pam)
importFrom(dplyr, group_by, summarise)

我的描述文件如下所示:

Package: YEAB
Title: Package to Analyze Data from Analysis of Behavior Experiments
Version: 0.1.0
Authors@R: c(
    person("Emmanuel", "Alcala", , "[email protected]", role = c("aut", "cre")),
    person("Rodrigo", "Sosa", , "[email protected]", role = "aut")
  )
Description: This is a colletion of functions aimed to analyze data from
    behavioral experiments from MED output and others. It also have
    functions to fit exponential or hyperbolic models from delay
    discounting tasks, exponential mixtures to IRTs, Gaussian plus ramp
    model for peak procedures data, etc.
License: CC0
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
Imports: 
    cluster,
    doParallel,
    rethinking,
    dplyr,
    foreach,
    ggplot2,
    grid,
    gridExtra,
    infotheo,
    ks,
    magrittr,
    minpack.lm,
    Polychrome,
    rmi,
    scales,
    sfsmisc,
    VGAM,
    MASS,
    zoo
License: CC-BY-4.0 + file LICENSE
Extdata: inst/extdata/fi60_raw.csv, inst/extdata/fi60_raw
Author: 'Emmanuel Alcala [aut, cre], Rodrigo Sosa [aut]'
Maintainer: Emmanuel Alcala <[email protected]>
Date: 2023-09-27

我在互联网上寻找解决方案,并尝试将“foreach”包更新到最新版本,但无济于事。更奇怪的是,如果我删除这些行:


importFrom(foreach,"%dopar%")
importFrom(foreach,foreach)

从 NAMESPACE 文件中,我仍然得到相同的“库”不是来自“namespace:foreach”的导出对象错误。

其他人发现这个问题了吗?

我在 R 包开发方面还很陌生,所以如果我在这里犯了一个菜鸟错误,我很抱歉。

r foreach namespaces
1个回答
0
投票

该错误告诉您 {foreach} 包没有名为

library
的函数。那是真实的。 R 中的
package::function
语法表示从
function
调用
package

您不应该在包中使用

library
来加载包。相反,正如您已经所做的那样,请使用
import
importFrom
来实现特定功能。

我非常确定您可以从包裹中删除包含

foreach::library(foreach)
的行,这样就可以解决问题而不会产生任何后果。

© www.soinside.com 2019 - 2024. All rights reserved.