[R-pkg-devel] Possible bug report/false positive

Ivan Krylov kry|ov@r00t @end|ng |rom gm@||@com
Thu Jan 6 15:37:01 CET 2022


On Wed, 5 Jan 2022 17:15:20 -0300
Igor L <igorlaltuf using gmail.com> wrote:

>   Found the platform-specific device:
>    'X11'

> how to solve it?

One of the tricks that work (in the sense that calls to functions using
non-standard evaluation don't result in warnings about "Undefined
global functions or variables") is to declare the variables locally,
inside the function:

protocolo <- X1 <- X2 <- ... X21 <- NULL
var <- readr::read_csv2(...) ...

Alternatively, since you know that the file always has 21 columns,
you can pass the variable to `colnames<-` instead of dplyr::rename,
together with a vector of column names you already have in the
nomes.colunas vector. This way, you won't need to declare the 21 dummy
variable.

By the way, you shouldn't declare at least download.file and unzip
functions as global variables. Instead, import them from the utils
package in your NAMESPACE (or using the @importFrom Roxygen tag, if you
use Roxygen).

There are other ways the package code could be improved:

 - There doesn't seem to be a need for the dynamically-named variable
   you create using assign(paste0('pedidos', i), var) and remove soon
   after; you can just use `var` instead of get(paste0('pedidos', i)).
 - If you're worried about leaving temporary variables around, move
   the loop body into a separate function so that anything you don't
   return from it would be cleaned up automatically.
 - You can future-proof your package by creating the URLs with
   paste0('https://dadosabertos-download.cgu.gov.br/FalaBR/Arquivos_FalaBR_Filtrado/Arquivos_csv_',
   year, '.zip') instead of hard-coding their list. It seems likely to
   me that once the 2022 Right to Information Law report is available,
   it'll have a predictable URL. If not, then you'll update the
   package (as you were going to anyway).
 - If you need to iterate over indices in a vector, use for (idx in
   seq_along(vector)) instead of for (i in vector) and match() to
   find the index. Though in this case, the code can be modified to
   avoid the need for the index in the loop body.

-- 
Best regards,
Ivan



More information about the R-package-devel mailing list