[datatable-help] Using := in .onLoad

Arunkumar Srinivasan aragorn168b at gmail.com
Tue Jan 20 14:51:29 CET 2015


Yes you've to add import(data.table) to your NAMESPACE file. What's
difficult about that? How do you import other packages?

And this is also FAQ 6.9 -
http://cran.r-project.org/web/packages/data.table/vignettes/datatable-faq.pdf


On Tue, Jan 20, 2015 at 2:48 PM, Juan Manuel Truppia <jmtruppia at gmail.com>
wrote:

> Yes, if I just list data.table in Imports in my DESCRIPTION file, then I
> have to use :: every time I call functions that are outside the base
> package. The only workaround is using import data.table in the NAMESPACE.
>
> On Tue, Jan 20, 2015, 10:41 Arunkumar Srinivasan <aragorn168b at gmail.com>
> wrote:
>
>> There should be no need to use :: to call data.table functions then. You
>> can use all the exported functions as such. And `:=` within DT[...] would /
>> should work just fine..
>>
>> Now that I understand your setup, why do you think you need to use :: for
>> every data.table function? What happens when you don't? And why did you get
>> error with :=?
>>
>> On Tue, Jan 20, 2015 at 2:36 PM, Juan Manuel Truppia <jmtruppia at gmail.com
>> > wrote:
>>
>>> Myself as the developer trying to use data.table functions from within
>>> my package
>>>
>>> On Tue, Jan 20, 2015, 10:32 Arunkumar Srinivasan <aragorn168b at gmail.com>
>>> wrote:
>>>
>>>> On Tue, Jan 20, 2015 at 2:22 PM, Juan Manuel Truppia <
>>>> jmtruppia at gmail.com> wrote:
>>>>
>>>>> Let's follow an example. I'm developing my own package. I add
>>>>> data.table to imports in my description file. This means I have to use the
>>>>> :: operator each time I want to call a data.table function.  Can I use :=
>>>>> in this setup?
>>>>>
>>>> "I have to use / Can I use" - here you refer to the user using your
>>>> package or yourself as the developer trying to use data.table functions and
>>>> := from within your package?
>>>>
>>>>
>>>>>
>>>>> On Tue, Jan 20, 2015, 10:01 Arunkumar Srinivasan <
>>>>> aragorn168b at gmail.com> wrote:
>>>>>
>>>>>> Juan,
>>>>>>
>>>>>>>
>>>>>>> I already know that.
>>>>>>>
>>>>>> Okay, great.
>>>>>>
>>>>>>> I usually struggle when using data.table inside my own packages. I
>>>>>>> start by listing it in imports only (and not importing anything)
>>>>>>>
>>>>>> "imports only (and not importing anything)"?  - what do you mean?
>>>>>>
>>>>>>> but end up depending on it, as for the users to be able to
>>>>>>> manipulate the data.tables with [ and :=.
>>>>>>>
>>>>>> It depends on whether you want the data.table NAMESPACE to be
>>>>>> attached or not. I think these posts may help:
>>>>>>
>>>>>> http://r.789695.n4.nabble.com/Re-R-CMD-check-checking-in-development-version-of-R-td4696125.html#none
>>>>>>
>>>>>> http://stackoverflow.com/questions/8637993/better-explanation-of-when-to-use-imports-depends
>>>>>>
>>>>>>
>>>>>>> I end up importing some or all of data.table also, because I don't
>>>>>>> know how to call := the :: notation.
>>>>>>>
>>>>>> I don't really follow this. Why do you want to use `::` along with
>>>>>> `:=`. The last post we just discussed that it can't be done, as it is not
>>>>>> designed to be used outside of  `[...]` and in very specific ways. Check
>>>>>> data.table:::`:=`. It is designed to error. This post might help:
>>>>>> http://stackoverflow.com/q/7033106/559784
>>>>>>
>>>>>>> My specific problem was on using := during on.Load.
>>>>>>>
>>>>>> It'd be useful to know what you are trying to do, along with your
>>>>>> code.
>>>>>>
>>>>>>> I already know how to use it, and know that it can only be used
>>>>>>> inside [.
>>>>>>> Maybe it is imperative to @import data.table to be able to use :=?
>>>>>>>
>>>>>> I don't follow exactly how you are trying to use := to answer this.
>>>>>>
>>>>>> Arun
>>>>>>
>>>>>>>
>>>>>>> On Mon, Jan 19, 2015, 19:35 Arunkumar Srinivasan <
>>>>>>> aragorn168b at gmail.com> wrote:
>>>>>>>
>>>>>>>> Within the square brackets in "DT[ .... ]" and even there, only in
>>>>>>>> `j` (as the error message points out).
>>>>>>>>
>>>>>>>> On Mon, Jan 19, 2015 at 11:31 PM, Juan Manuel Truppia <
>>>>>>>> jmtruppia at gmail.com> wrote:
>>>>>>>>
>>>>>>>>> Arun, what does "within the frame of data.table" mean?
>>>>>>>>>
>>>>>>>>> On Mon, Jan 19, 2015, 19:17 Arunkumar Srinivasan <
>>>>>>>>> aragorn168b at gmail.com> wrote:
>>>>>>>>>
>>>>>>>>>> Juan,
>>>>>>>>>>
>>>>>>>>>> `:=` is designed to be used only within the frame of data.table.
>>>>>>>>>>
>>>>>>>>>> On Mon, Jan 19, 2015 at 10:45 PM, Juan Manuel Truppia <
>>>>>>>>>> jmtruppia at gmail.com> wrote:
>>>>>>>>>>
>>>>>>>>>>> Hi, I'm using data.table inside my own packages. I'm having some
>>>>>>>>>>> trouble using data.table functions on my .onLoad method.
>>>>>>>>>>> I'm actually depending (not importing) data.table, but even
>>>>>>>>>>> then, I can't get := to work in .onLoad.
>>>>>>>>>>> I'm using the `:=`(a = x, b = y) version, and getting
>>>>>>>>>>>
>>>>>>>>>>> Error in `:=`(a = x) :
>>>>>>>>>>> Check that is.data.table(DT) == TRUE. Otherwise, := and
>>>>>>>>>>> `:=`(...) are defined for use in j, once only and in particular ways. See
>>>>>>>>>>> help(":=").
>>>>>>>>>>>
>>>>>>>>>>> If I comment that, and then run it from the console after the
>>>>>>>>>>> package is loaded, it works.
>>>>>>>>>>>
>>>>>>>>>>> Any ideas?
>>>>>>>>>>>
>>>>>>>>>>> _______________________________________________
>>>>>>>>>>> datatable-help mailing list
>>>>>>>>>>> datatable-help at lists.r-forge.r-project.org
>>>>>>>>>>>
>>>>>>>>>>> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20150120/53057420/attachment.html>


More information about the datatable-help mailing list