开始创建一个程序包,我构建了一些函数,然后运行devtools :: check()以确保我按计划进行。下面,我复制devtools::check()
命令的整个输出。有两个音符使我感到惊讶。我希望通过清理这两件事,使其他事情变得更容易修复,因此我将从它们开始。我并不是要解决检查中的所有问题,而只是想了解这两个问题。第一个是:
DESCRIPTION文件中未提及文件许可
另一个在
之后检查R代码是否存在问题(3.7秒)
在哪里有很多消息“ 没有可见的全局函数定义”,尽管这些函数在说明文件中导入的程序包中。
以下是DESCRIPTION文件。整个可复制的代码可以在https://github.com/rexmacey/factorModel中找到。之后是devtools :: check命令的输出。
Package: factorModel
Title: Factor Model Creation and Evaluation
Version: 0.0.0.9000
Authors@R: person("Rex", "Macey", email = "rex@macey.us", role = c("aut", "cre"))
Description: Creates and tests factor models.
Depends: R (>= 3.5.0)
License: GPL-2
Encoding: UTF-8
LazyData: true
Imports:
dplyr,
knitr,
lubridate,
ggplot2,
reshape2,
tidyquant
Suggests:
utils,
testthat
VignetteBuilder:
utils
RoxygenNote: 6.1.1
devtools :: check的输出
> check()
Updating factorModel documentation
Writing NAMESPACE
Loading factorModel
Writing NAMESPACE
-- Building -------------------------------------------------------------- factorModel --
Setting env vars:
* CFLAGS : -Wall -pedantic
* CXXFLAGS : -Wall -pedantic
* CXX11FLAGS: -Wall -pedantic
-----------------------------------------------------------------------------------------
√ checking for file 'C:\Users\Rex\Google Drive\RedTortoise\Research - RT\factorModel/DESCRIPTION' (449ms)
- preparing 'factorModel': (441ms)
√ checking DESCRIPTION meta-information ...
- excluding invalid files
Subdirectory 'R' contains invalid file names:
'desktop.ini'
Subdirectory 'man' contains invalid file names:
'desktop.ini'
- checking for LF line-endings in source and make files and shell scripts
- checking for empty or unneeded directories
- looking to see if a 'data/datalist' file should be added
- building 'factorModel_0.0.0.9000.tar.gz'
-- Checking -------------------------------------------------------------- factorModel --
Setting env vars:
* _R_CHECK_CRAN_INCOMING_REMOTE_: FALSE
* _R_CHECK_CRAN_INCOMING_ : FALSE
* _R_CHECK_FORCE_SUGGESTS_ : FALSE
-- R CMD check --------------------------------------------------------------------------
- using log directory 'C:/Users/Rex/AppData/Local/Temp/Rtmp4ig3Oj/factorModel.Rcheck' (400ms)
- using R version 3.5.1 (2018-07-02)
- using platform: x86_64-w64-mingw32 (64-bit)
- using session charset: ISO8859-1
- using options '--no-manual --as-cran'
√ checking for file 'factorModel/DESCRIPTION'
- this is package 'factorModel' version '0.0.0.9000'
- package encoding: UTF-8
√ checking package namespace information
√ checking package dependencies (952ms)
√ checking if this is a source package ...
√ checking if there is a namespace
√ checking for .dll and .exe files
√ checking for hidden files and directories ...
√ checking for portable file names ...
√ checking whether package 'factorModel' can be installed (5.1s)
√ checking package directory (767ms)
√ checking DESCRIPTION meta-information (644ms)
N checking top-level files
File
LICENSE
is not mentioned in the DESCRIPTION file.
√ checking for left-over files ...
√ checking index information
√ checking package subdirectories ...
√ checking R files for non-ASCII characters ...
√ checking R files for syntax errors ...
√ checking whether the package can be loaded ...
√ checking whether the package can be loaded with stated dependencies ...
√ checking whether the package can be unloaded cleanly ...
√ checking whether the namespace can be loaded with stated dependencies ...
√ checking whether the namespace can be unloaded cleanly (521ms)
√ checking loading without being on the library search path (697ms)
√ checking dependencies in R code ...
√ checking S3 generic/method consistency (609ms)
√ checking replacement functions ...
√ checking foreign function calls ...
N checking R code for possible problems (3.6s)
AddFactor: no visible global function definition for '%>%'
AddFactor: no visible global function definition for 'filter'
GetFundReturns: no visible global function definition for '%>%'
GetFundReturns: no visible global function definition for 'tq_get'
GetFundReturns: no visible global function definition for '%m+%'
GetFundReturns: no visible global function definition for 'days'
GetFundReturns: no visible global function definition for 'group_by'
GetFundReturns: no visible binding for global variable 'symbol'
GetFundReturns: no visible global function definition for
'tq_transmute'
GetFundReturns: no visible binding for global variable 'adjusted'
GetFundReturns: no visible binding for global variable 'periodReturn'
GetFundReturns: no visible global function definition for 'filter'
plot_corr: no visible global function definition for 'cor'
plot_corr: no visible global function definition for 'melt'
plot_corr: no visible global function definition for 'ggplot'
plot_corr: no visible global function definition for 'aes'
plot_corr: no visible binding for global variable 'Var2'
plot_corr: no visible binding for global variable 'Var1'
plot_corr: no visible binding for global variable 'value'
plot_corr: no visible global function definition for 'geom_tile'
plot_corr: no visible global function definition for
'scale_fill_gradient2'
plot_corr: no visible global function definition for 'theme_minimal'
plot_corr: no visible global function definition for 'theme'
plot_corr: no visible global function definition for 'element_text'
plot_corr: no visible global function definition for 'coord_fixed'
plot_corr: no visible global function definition for 'xlab'
plot_corr: no visible global function definition for 'ylab'
plot_corr: no visible global function definition for 'geom_text'
plot_corr: no visible global function definition for 'element_blank'
plot_corr: no visible global function definition for 'guides'
plot_corr: no visible global function definition for 'guide_colorbar'
Undefined global functions or variables:
%>% %m+% Var1 Var2 adjusted aes coord_fixed cor days element_blank
element_text filter geom_text geom_tile ggplot group_by
guide_colorbar guides melt periodReturn scale_fill_gradient2 symbol
theme theme_minimal tq_get tq_transmute value xlab ylab
Consider adding
importFrom("stats", "cor", "filter")
to your NAMESPACE file.
Found the following calls to data() loading into the global environment:
File 'factorModel/R/loadLibraries.r':
data(factorReturns)
data("factorReturns.US")
data(factorReturns.Intl)
data(factorReturns.EM)
data("factorGroups")
See section 'Good practice' in '?data'.
√ checking Rd files ...
√ checking Rd metadata ...
√ checking Rd line widths ...
√ checking Rd cross-references ...
√ checking for missing documentation entries ...
√ checking for code/documentation mismatches (730ms)
√ checking Rd \usage sections (816ms)
√ checking Rd contents ...
√ checking for unstated dependencies in examples ...
W checking contents of 'data' directory ...
Files not of a type allowed in a 'data' directory:
'desktop.ini'
Please use e.g. 'inst/extdata' for non-R data files
√ checking data for non-ASCII characters ...
√ checking data for ASCII and uncompressed saves ...
E checking examples (653ms)
Running examples in 'factorModel-Ex.R' failed
The error most likely occurred in:
> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: AddFactor
> ### Title: Add a Factor
> ### Aliases: AddFactor
>
> ### ** Examples
>
> AddFactor(factorReturns=factorReturns.US, newFactorReturns=newFactorReturns, calcExcess=TRUE)
Error in FindMaxCommonDateRange(factorReturns$date, newFactorReturns$date) :
object 'newFactorReturns' not found
Calls: AddFactor -> FindMaxCommonDateRange
Execution halted
√ checking for unstated dependencies in 'tests' ...
- checking tests ...
E Running 'testthat.R'
Running the tests in 'tests/testthat.R' failed.
Last 13 lines of output:
5: eval(quote(`_fseq`(`_lhs`)), env, env)
6: `_fseq`(`_lhs`)
7: freduce(value, `_function_list`)
8: withVisible(function_list[[k]](value))
9: function_list[[k]](value)
10: filter(., date >= dateRange["start"] & date <= dateRange["end"])
11: Ops.Date(date, dateRange["start"])
12: NextMethod(.Generic)
== testthat results ===========================================================
OK: 0 SKIPPED: 0 FAILED: 1
1. Error: AddFactor adds a column, restricts dates (@test_AddFactor.r#9)
Error: testthat unit tests failed
Execution halted
See
'C:/Users/Rex/AppData/Local/Temp/Rtmp4ig3Oj/factorModel.Rcheck/00check.log'
for details.
-- R CMD check results -------------------------------------- factorModel 0.0.0.9000 ----
Duration: 22.1s
> checking examples ... ERROR
Running examples in 'factorModel-Ex.R' failed
The error most likely occurred in:
> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: AddFactor
> ### Title: Add a Factor
> ### Aliases: AddFactor
>
> ### ** Examples
>
> AddFactor(factorReturns=factorReturns.US, newFactorReturns=newFactorReturns, calcExcess=TRUE)
Error in FindMaxCommonDateRange(factorReturns$date, newFactorReturns$date) :
object 'newFactorReturns' not found
Calls: AddFactor -> FindMaxCommonDateRange
Execution halted
> checking tests ...
See below...
> checking contents of 'data' directory ... WARNING
Files not of a type allowed in a 'data' directory:
'desktop.ini'
Please use e.g. 'inst/extdata' for non-R data files
> checking top-level files ... NOTE
File
LICENSE
is not mentioned in the DESCRIPTION file.
> checking R code for possible problems ... NOTE
AddFactor: no visible global function definition for '%>%'
AddFactor: no visible global function definition for 'filter'
GetFundReturns: no visible global function definition for '%>%'
GetFundReturns: no visible global function definition for 'tq_get'
GetFundReturns: no visible global function definition for '%m+%'
GetFundReturns: no visible global function definition for 'days'
GetFundReturns: no visible global function definition for 'group_by'
GetFundReturns: no visible binding for global variable 'symbol'
GetFundReturns: no visible global function definition for
'tq_transmute'
GetFundReturns: no visible binding for global variable 'adjusted'
GetFundReturns: no visible binding for global variable 'periodReturn'
GetFundReturns: no visible global function definition for 'filter'
plot_corr: no visible global function definition for 'cor'
plot_corr: no visible global function definition for 'melt'
plot_corr: no visible global function definition for 'ggplot'
plot_corr: no visible global function definition for 'aes'
plot_corr: no visible binding for global variable 'Var2'
plot_corr: no visible binding for global variable 'Var1'
plot_corr: no visible binding for global variable 'value'
plot_corr: no visible global function definition for 'geom_tile'
plot_corr: no visible global function definition for
'scale_fill_gradient2'
plot_corr: no visible global function definition for 'theme_minimal'
plot_corr: no visible global function definition for 'theme'
plot_corr: no visible global function definition for 'element_text'
plot_corr: no visible global function definition for 'coord_fixed'
plot_corr: no visible global function definition for 'xlab'
plot_corr: no visible global function definition for 'ylab'
plot_corr: no visible global function definition for 'geom_text'
plot_corr: no visible global function definition for 'element_blank'
plot_corr: no visible global function definition for 'guides'
plot_corr: no visible global function definition for 'guide_colorbar'
Undefined global functions or variables:
%>% %m+% Var1 Var2 adjusted aes coord_fixed cor days element_blank
element_text filter geom_text geom_tile ggplot group_by
guide_colorbar guides melt periodReturn scale_fill_gradient2 symbol
theme theme_minimal tq_get tq_transmute value xlab ylab
Consider adding
importFrom("stats", "cor", "filter")
to your NAMESPACE file.
Found the following calls to data() loading into the global environment:
File 'factorModel/R/loadLibraries.r':
data(factorReturns)
data("factorReturns.US")
data(factorReturns.Intl)
data(factorReturns.EM)
data("factorGroups")
See section 'Good practice' in '?data'.
-- Test failures ---------------------------------------------------------- testthat ----
> library(testthat)
> library(factorModel)
>
> test_check("factorModel")
-- 1. Error: AddFactor adds a column, restricts dates (@test_AddFactor.r#9) --
comparison (5) is possible only for atomic and list types
1: AddFactor(fr1, fr2, TRUE) at testthat/test_AddFactor.r:9
2: factorReturns %>% filter(date >= dateRange["start"] & date <= dateRange["end"])
3: withVisible(eval(quote(`_fseq`(`_lhs`)), env, env))
4: eval(quote(`_fseq`(`_lhs`)), env, env)
5: eval(quote(`_fseq`(`_lhs`)), env, env)
6: `_fseq`(`_lhs`)
7: freduce(value, `_function_list`)
8: withVisible(function_list[[k]](value))
9: function_list[[k]](value)
10: filter(., date >= dateRange["start"] & date <= dateRange["end"])
11: Ops.Date(date, dateRange["start"])
12: NextMethod(.Generic)
== testthat results ===========================================================
OK: 0 SKIPPED: 0 FAILED: 1
1. Error: AddFactor adds a column, restricts dates (@test_AddFactor.r#9)
Error: testthat unit tests failed
Execution halted
2 errors x | 1 warning x | 2 notes x
答案 0 :(得分:1)
您肯定想看看Hadley Wickham的书R packages。他还在Checking上有一章。
由于未提到“许可”而要删除NOTE,则应将License: GPL-3
更改为License: GPL-3 + file LICENSE
(另请参见http://r-pkgs.had.co.nz/description.html#license)。或者,您应该删除文件LICENSE。
关于no visible global function definition
,您需要定义函数的来源。它们是由您在包装中定义的。或者它们需要导入。要从dplyr导入group_by()
,您需要执行以下操作(另请参见http://r-pkgs.had.co.nz/namespace.html#imports):
在Description文件中列出dplyr(例如,在“导入”下)
通过任一方式导入group_by()
group_by()
替换为dplyr::group_by()
,或@importFrom dplyr group_by
导入函数。这些是最重要的选项,您可以在http://r-pkgs.had.co.nz/namespace.html中进行阅读。