Starting to create a package, I built a few functions and then ran devtools::check() to make sure I was on track. Below I copy the entire output of the devtools::check()
command. There are two notes that surprise me. I'm hoping by cleaning these two things up, the other things become easier to fix so I am starting with them. I'm not trying to solve all of the issues from check, just trying to understand these two. The first is:
File LICENSE is not mentioned in the DESCRIPTION file
The other comes after
checking R code for possible problems (3.7s)
where are are many messages "no visible global function definition" despite these functions being in packages which are imported in the DESCRIPTION file.
Following is the DESCRIPTION file. The entire reproducible code may be found in https://github.com/rexmacey/factorModel . After that is the output from the devtools::check command.
Package: factorModel
Title: Factor Model Creation and Evaluation
Version: 0.0.0.9000
Authors@R: person("Rex", "Macey", email = "[email protected]", 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
Output from the 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
You definitely want to check out the book R packages by Hadley Wickham. He also has a chapter on Checking.
The get rid of the NOTE because of "LICENSE is not mentioned", you should change License: GPL-3
to License: GPL-3 + file LICENSE
(see also http://r-pkgs.had.co.nz/description.html#license). Or you should delete the file LICENSE.
With respect to no visible global function definition
, you need to define where you're functions come from. They are either defined by you in your package. Or they need to be imported. To import, say, group_by()
from dplyr, you need to do the following (see also http://r-pkgs.had.co.nz/namespace.html#imports):
List dplyr in the DESCRIPTION file (e.g., under Imports)
Import group_by()
by either
group_by()
with dplyr::group_by()
, or@importFrom dplyr group_by
.These are the most important options and you can read up on that in http://r-pkgs.had.co.nz/namespace.html.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With