<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>FYI <br><br>----------------<div>Sent from mobile device, please excuse possible typos</div></div><div><br>Begin forwarded message:<br><br></div><blockquote type="cite"><div><b>From:</b> Kurt Hornik <<a href="mailto:Kurt.Hornik@wu.ac.at">Kurt.Hornik@wu.ac.at</a>><br><b>Date:</b> 2 Jul 2015 11:28:45 CEST<br><b>To:</b> <a href="mailto:CRAN@R-project.org">CRAN@R-project.org</a><br><b>Subject:</b> <b>CRAN packages maintained by you</b><br><b>Reply-To:</b> <a href="mailto:Kurt.Hornik@wu.ac.at">Kurt.Hornik@wu.ac.at</a><br><br></div></blockquote><blockquote type="cite"><div><span></span><br><span>Dear CRAN package maintainers,</span><br><span></span><br><span>You may already have seen the following news item for r-devel:</span><br><span></span><br><span> * 'R CMD check --as-cran' now checks code usage (via 'codetools')</span><br><span> with only the base package attached, so that functions from</span><br><span> default packages other than base which are used in the package</span><br><span> code but not imported are reported as undefined globals.</span><br><span></span><br><span>This may result in lots of notes about undefined globals which can be</span><br><span>found in the default packages. The change was made because even though</span><br><span>the default packages (stats, graphics, ...) are typically loaded and</span><br><span>attached, bindings not found in the package code itself, the imports or</span><br><span>base are searched for along the search path starting with the global</span><br><span>environment, and there is no control over what is actually found there.</span><br><span>Therefore, undefined globals corresponding to functions or variables in</span><br><span>the default packages, really need to be imported into the package</span><br><span>namespace.</span><br><span></span><br><span>With current versions of r-devel, one can get a convenient summary of</span><br><span>all undefined globals, which can be used for programmatically generating</span><br><span>the missing imports as follows. </span><br><span></span><br><span>One package currently gives</span><br><span></span><br><span>* checking R code for possible problems ... NOTE</span><br><span>choose_palette : SaveColorsToFile: no visible global function</span><br><span> definition for ‘write.table’</span><br><span>choose_palette : ShowExample: no visible global function definition for</span><br><span> ‘dev.list’</span><br><span>choose_palette : ShowExample: no visible global function definition for</span><br><span> ‘dev.new’</span><br><span>choose_palette : ShowExample: no visible global function definition for</span><br><span> ‘dev.cur’</span><br><span>choose_palette : ShowExample: no visible global function definition for</span><br><span> ‘par’</span><br><span>choose_palette : RegenExample: no visible global function definition</span><br><span> for ‘dev.list’</span><br><span>choose_palette : RegenExample: no visible global function definition</span><br><span> for ‘dev.set’</span><br><span>choose_palette : PlotMap: no visible global function definition for</span><br><span> ‘polygon’</span><br><span><...................................................................></span><br><span>choose_palette : PlotMosaic: no visible global function definition for</span><br><span> ‘image’</span><br><span>choose_palette : PlotLines: no visible global function definition for</span><br><span> ‘segments’</span><br><span>choose_palette: no visible global function definition for</span><br><span> ‘compareVersion’</span><br><span>choose_palette: no visible global function definition for ‘dev.list’</span><br><span>choose_palette: no visible global function definition for ‘dev.off’</span><br><span>desaturate: no visible global function definition for ‘col2rgb’</span><br><span>Undefined global functions or variables:</span><br><span> barplot col2rgb compareVersion cutree dev.cur dev.list dev.new</span><br><span> dev.off dev.set dist dnorm hclust head image na.omit par persp pie</span><br><span> polygon rect rnorm runif segments volcano write.table</span><br><span></span><br><span>Using the above output, do</span><br><span></span><br><span>txt <- "barplot col2rgb compareVersion cutree dev.cur dev.list dev.new</span><br><span> dev.off dev.set dist dnorm hclust head image na.omit par persp pie</span><br><span> polygon rect rnorm runif segments volcano write.table"</span><br><span></span><br><span>and use</span><br><span></span><br><span>imports_for_undefined_globals <-</span><br><span>function(txt, lst, selective = TRUE)</span><br><span>{</span><br><span> if(!missing(txt))</span><br><span> lst <- scan(what = character(), text = txt, quiet = TRUE)</span><br><span> nms <- lapply(lst, find)</span><br><span> ind <- sapply(nms, length) > 0L</span><br><span> imp <- split(lst[ind], substring(unlist(nms[ind]), 9L))</span><br><span> if(selective) {</span><br><span> sprintf("importFrom(%s)",</span><br><span> vapply(Map(c, names(imp), imp),</span><br><span> function(e)</span><br><span> paste0("\"", e, "\"", collapse = ", "),</span><br><span> ""))</span><br><span> } else {</span><br><span> sprintf("import(\"%s\")", names(imp))</span><br><span> }</span><br><span>} </span><br><span></span><br><span>to get</span><br><span></span><br><span>R> writeLines(imports_for_undefined_globals(txt))</span><br><span>importFrom("datasets", "volcano")</span><br><span>importFrom("grDevices", "col2rgb", "dev.cur", "dev.list", "dev.new", "dev.off", "dev.set")</span><br><span>importFrom("graphics", "barplot", "image", "par", "persp", "pie", "polygon", "rect", "segments")</span><br><span>importFrom("stats", "cutree", "dist", "dnorm", "hclust", "na.omit", "rnorm", "runif")</span><br><span>importFrom("utils", "compareVersion", "head", "write.table")</span><br><span></span><br><span>For non-selective importing, use</span><br><span></span><br><span>R> writeLines(imports_for_undefined_globals(txt, selective = FALSE))</span><br><span>import("datasets")</span><br><span>import("grDevices")</span><br><span>import("graphics")</span><br><span>import("stats")</span><br><span>import("utils")</span><br><span></span><br><span>Of course, namespaces newly imported from also need to be listed in the</span><br><span>Imports: field of DESCRIPTION.</span><br><span></span><br><span>Please make sure you make the necessary changes before you submit new</span><br><span>versions of your package to CRAN.</span><br><span></span><br><span>Best</span><br><span>-k</span><br><span></span><br></div></blockquote></body></html>