Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R package compilation with dependency on data.table

Tags:

r

data.table

I am trying to create an R package with a function using the J of data.table. When I run R CMD check, I have a NOTE : no visible global function definition for 'J' although I've added data.table as a dependency in the DESCRIPTION file.

Package: rfPred
Type: Package
Title: Assign rfPred functional prediction scores to a missense variants list
Version: 1.0
Date: 2013-03-14
Author: me
Maintainer:me
Depends: data.table
[..]

I've tried to use another function of the data.table package in the package I want to create, but I haven't the same problem as for J.

Do you have a solution ?

like image 613
user2169834 Avatar asked Mar 14 '13 12:03

user2169834


1 Answers

J() as an independent function has been removed from data.table. It is only for use inside DT[...], where it still works. But for packages depending on data.table and using J() correctly, like yours, an extra step is required to avoid the NOTE (see below).

First the background and why J() was removed. Extracts from NEWS :

v1.8.2 (Jul 2012) :

  • The J() alias is now deprecated outside DT[...], but will still work inside DT[...], as in DT[J(...)]. J() is conflicting with function J() in package XLConnect (#1747) and rJava (#2045). For data.table to change is easier, with some efficiency advantages too. The next version of data.table will issue a warning from J() when used outside DT[...]. The version after will remove it. Only then will the conflict with rJava and XLConnect be resolved. Please use data.table() directly instead of J(), outside DT[...].

v1.8.4 (Nov 2012) :

  • J() now issues a warning (when used outside DT[...]) that using it outside DT[...] is deprecated. See item below in v1.8.2. Use data.table() directly instead of J(), outside DT[...]. Or, define an alias yourself. J() will continue to work inside DT[...] as documented.

v1.8.8 (now on CRAN, Mar 2013) :

  • The J() alias is now removed outside DT[...], but will still work inside DT[...]; i.e., DT[J(...)] is fine. As warned in v1.8.2 (see below in this file) and deprecated with warning() in v1.8.4. This resolves the conflict with function J() in package XLConnect (#1747) and rJava (#2045). Please use data.table() directly instead of J(), outside DT[...].

As an aside, there was also a recent related thread on r-devel :
http://r.789695.n4.nabble.com/conflict-between-rJava-and-data-table-tp4659935p4659984.html

Now for the NOTE produced by R CMD check on your package

Your package is using J() inside DT[...] and working fine. The only issue is the NOTE from R CMD check :

no visible global function definition for 'J'

Here are all the known options :

  • Ignore the NOTE. (I don't like this either but just as an option). Only WARNING and ERROR have to be dealt with.
  • Replace J by list. It's equivalent.
  • Define J=NULL somewhere in your package. (We looked at data.table exporting J=NULL so you wouldn't have to but decided not to since any data.table user typing J at the prompt would see NULL which may be confusing.)
  • Or use ?utils::globalVariables as Ben Bolker suggested in comments.

Further background on this particular NOTE is in this related question :

No visible binding for global variable Note in R CMD check

like image 129
Matt Dowle Avatar answered Sep 27 '22 20:09

Matt Dowle