Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use .datatable.aware when data.table in Sugggests #3818

Merged
merged 1 commit into from
Sep 11, 2019

Conversation

tdhock
Copy link
Member

@tdhock tdhock commented Sep 4, 2019

Hi this PR was requested by @jangorecki after a short discussion on the linked issue (#2053). The change to the vignette adds some discussion about what to do when data.table is in Suggests (not imported) and used only in tests.

@codecov
Copy link

codecov bot commented Sep 4, 2019

Codecov Report

Merging #3818 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3818   +/-   ##
=======================================
  Coverage   99.41%   99.41%           
=======================================
  Files          71       71           
  Lines       13265    13265           
=======================================
  Hits        13188    13188           
  Misses         77       77

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3d0dc92...cd6135d. Read the comment docs.

@@ -82,6 +82,8 @@ test_that("generate dt", { expect_true(nrow(gen()) == 100) })
test_that("aggregate dt", { expect_true(nrow(aggr(gen())) < 100) })
```

If `data.table` is in Suggests (but not Imports) then you need to declare `.datatable.aware=TRUE` in one of the R/* files to avoid "object not found" errors when testing via `testthat::test_package` or `testthat::test_check`.
Copy link
Member

@jangorecki jangorecki Sep 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you confirm this statement is also valid when NAMESPACE is present? to not have it blank you can import anything from base R, or export dummy function there

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

works with blank NAMESPACE, and when I do importFrom("stats", "sd")

When using a package as a suggested dependency, you should not `import` it in the `NAMESPACE` file. Just mention it in the `DESCRIPTION` file. You also _must_ use the `data.table::` prefix when calling `data.table` functions because none of them are imported.
When using a package as a suggested dependency, you should not `import` it in the `NAMESPACE` file. Just mention it in the `DESCRIPTION` file.
When using `data.table` functions in package code (R/* files) you need to use the `data.table::` prefix because none of them are imported.
When using `data.table` in package tests (e.g. tests/testthat/test* files), you need to declare `.datatable.aware=TRUE` in one of the R/* files.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, good to know if presence of NAMESPACE file matters

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think NAMESPACE matters. presence of .datatable.aware=TRUE means no error on testthat::test_package (as expected); absence means unexpected "object not found" error.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all this can be answered with cedta code:

isTRUE(ns$.datatable.aware)

where ns is the namespace of the call, so .datatable.aware covers all bases.

Earlier we see:

"data.table" %chin% names(getNamespaceImports(ns))
# getNamespaceImports main code:
.getNamespaceInfo(ns, "imports")

AFAICT these names correspond to importFrom or import statements in NAMESPACE

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure I understand. can you please clarify? are you saying that you may be able to modify cedta to fix the issue, without having me add .datatable.aware=TRUE in my package? that would be ideal.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, I think without being in imports, .datatable.aware is probably the canonical way to do things. .datatable.aware=TRUE seems pretty minimal after all! Just a quick line of code to signal to data.table that you know we're here.

My comment was hoping to shed light on the discussion on whether NAMESPACE matters

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@mattdowle mattdowle added this to the 1.12.4 milestone Sep 11, 2019
@mattdowle mattdowle merged commit 460b91b into Rdatatable:master Sep 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants