10

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 ?

GSee
  • 48,880
  • 13
  • 125
  • 145
user2169834
  • 103
  • 6
  • 1
    Could you show us your `description` file? Also which version of `data.table` are you using? – Arun Mar 14 '13 at 13:06
  • 1
    You should also document how you are using `J`. – IRTFM Mar 14 '13 at 13:24
  • The Description file is the following : 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 – user2169834 Mar 14 '13 at 15:00
  • And I'm using the version 1.8.8 of data.table. – user2169834 Mar 14 '13 at 15:05

1 Answers1

10

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

Community
  • 1
  • 1
Matt Dowle
  • 58,872
  • 22
  • 166
  • 224
  • I'm using J() inside data.table, but the compilation program doesn't see it – user2169834 Mar 14 '13 at 15:04
  • How can I say to the R compilater that my package depends on J() ? – user2169834 Mar 14 '13 at 15:26
  • 1
    @user2169834 Then as DWin suggested, we really do need to see your line of code using `J()`. All I can think is that you're not using `J()` in quite the right way. – Matt Dowle Mar 14 '13 at 15:33
  • x is a data.table and my code is the following : variants[j:(j-1+nrow(scores)),]$rfPred<-x[J(scores[,1], scores[,2], scores[,3], scores[,4],scores[,5])]$rfPred I can fix the problem in replacing J() by data.table() in my code, but I don't understand why the R compilator doesn't recognize J() although the function runs well. – user2169834 Mar 15 '13 at 08:57
  • 1
    `J <- NULL` will work; you can also use `tools::globalVariables` to work around the NOTE, if you want – Ben Bolker Mar 15 '13 at 13:24
  • 1
    @BenBolker Cool. `globalVariables()` is news to me, thanks. Found it in `utils:` btw. – Matt Dowle Mar 15 '13 at 13:34