Usethis: Add `use_import_from()` to other functions

Created on 3 Mar 2021  路  8Comments  路  Source: r-lib/usethis

Definitely use_tibble(), maybe use_pipe(), but not use_data_table()

All 8 comments

You know, I'm actually a little skeptical that @import data.table is the best approach, anyway. It seems like from https://rdatatable.gitlab.io/data.table/articles/datatable-importing.html that a more surgical set of @importFroms might be sufficient to cover the unique operators that complicate importing the pkg. I haven't looked into using that approach, but having tested use_data_table(), @import data.table really adds a lot to the NS

Maybe @MichaelChirico can chime in.

Yes please @MichaelChirico! use_tibble() is really a just-enough approach to get exported tibbles functioning correctly in a pkg. It seems like a smaller set of imports might be able to do the same for data.table. Maybe something like @importFrom data.table data.table := .SD .BY .N .I .GRP .NGRP .EACHI (edit: updated typos in object names)

Sorry I'm not sure the full context, but yes that looks right (.SD not SD of course, ditto .EACHI) for a list of symbols crucial to import to stop R CMD check from all of the "Undefined global" warnings. Also .NATURAL.

I might add setDT and as.data.table to complement data.table as well.

Thanks @MichaelChirico -- sorry for the lack of context! #1377 introduced use_import_from(), which is sort of a generalized version of the internal code for use_tibble() and fellows. It doesn't translate to use_data_table() well since this implementation is really just for @importFrom. But, as mentioned, I'm wondering if a more minimal set of imports is a bit more consistent with what use_tibble() does--enough to support exporting functioning data.tables as data objects, but not much more. That would also mean the internal code for use_data_table() could use use_import_from()

I think the transition plan we'd like is to reduce use_tibble() and use_data_table() to a sequence of calls of use_import_from().

Then maybe we "gift" these functions back to their respective packages one day? Those packages obviously won't depend on usethis, so the helper would just print the commands a usethis user could use to implement the package's recommended @importFroms.

OK I see what you mean I think. Yes @import data.table is a straightforward blanket approach, not particularly committed to it.

@importFrom data.table data.table := .SD .BY .N .I .GRP .NGRP .EACHI

looks great to me. let me try and get you some data on what our most common downstream function imports are as well.

From a pretty basic loop over reverse Imports of data.table, I think just data.table() in addition to those symbols makes sense:

              fun count usage_per_pkg
 1:    data.table  6518     4.2966381
 2:           set  3006     1.9815425
 3:      setnames  1963     1.2940013
 4:     rbindlist  1615     1.0646012
 5: as.data.table  1599     1.0540541
 6:         first  1320     0.8701384
 7:          copy  1293     0.8523401
 8:       setkeyv   853     0.5622940
 9:         setDT   811     0.5346078
10:          melt   681     0.4489123
Was this page helpful?
0 / 5 - 0 ratings

Related issues

llrs picture llrs  路  3Comments

EmilHvitfeldt picture EmilHvitfeldt  路  3Comments

uribo picture uribo  路  5Comments

atheobold picture atheobold  路  7Comments

jennybc picture jennybc  路  4Comments