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

exclude ... from tables() search #5199

Merged
merged 7 commits into from
Oct 8, 2021
Merged

exclude ... from tables() search #5199

merged 7 commits into from
Oct 8, 2021

Conversation

MichaelChirico
Copy link
Member

Closes #5197

R/tables.R Outdated
{
# Prints name, size and colnames of all data.tables in the calling environment by default
all_obj = objects(envir=env, all.names=TRUE)
# include "hidden" objects (starting with .) via all.names=TRUE, but exclude ... specifically, #5197
all_obj = grep("...", objects(envir=env, all.names=TRUE), invert=TRUE, fixed=TRUE, value=TRUE)
Copy link
Member Author

Choose a reason for hiding this comment

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

btw any reason to use objects() here? it looks like an exact duplicate of ls(), but probably less well-known...

Copy link
Member

Choose a reason for hiding this comment

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

nope - just I got used to objects(). I didn't know ls() was an exact duplicate of objects(), that's interesting, so I don't mind using ls() instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

is_DT = which(vapply_1b(all_obj, function(x) is.data.table(get(x, envir=env))))
if (!length(is_DT)) {
# include "hidden" objects (starting with .) via all.names=TRUE, but exclude ... specifically, #5197
all_obj = grep("...", objects(envir=env, all.names=TRUE, sorted=order.col == "NAME"), invert=TRUE, fixed=TRUE, value=TRUE)
Copy link
Member Author

Choose a reason for hiding this comment

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

we could also pass pattern="^([^.]|[.][^.]|[.][.][^.])" to do it in one call, but that's pretty ugly, and anyway objects() itself is just calling grep() so there's no efficiency benefit (i.e., pattern is not being handled in C), so wrapping in grep() does the same thing with a more readable grep() call.

Copy link
Member

@mattdowle mattdowle Nov 13, 2022

Choose a reason for hiding this comment

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

objects() only calls grep() when pattern is not missing, iiuc. But pattern is missing in this objects() call. So doesn't adding grep here add overhead of grep when all we want to do is remove the string "..." if it's present?

@codecov
Copy link

codecov bot commented Oct 5, 2021

Codecov Report

Merging #5199 (0cd1ad1) into master (d87150c) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #5199   +/-   ##
=======================================
  Coverage   99.51%   99.51%           
=======================================
  Files          77       77           
  Lines       14527    14528    +1     
=======================================
+ Hits        14456    14457    +1     
  Misses         71       71           
Impacted Files Coverage Δ
R/tables.R 100.00% <100.00%> (ø)

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 d87150c...0cd1ad1. Read the comment docs.

@mattdowle mattdowle added this to the 1.14.3 milestone Oct 8, 2021
@mattdowle mattdowle merged commit 52847f0 into master Oct 8, 2021
@mattdowle mattdowle deleted the MichaelChirico-patch-3 branch October 8, 2021 07:50
if (!length(is_DT)) {
# include "hidden" objects (starting with .) via all.names=TRUE, but exclude ... specifically, #5197
all_obj = grep("...", objects(envir=env, all.names=TRUE, sorted=order.col == "NAME"), invert=TRUE, fixed=TRUE, value=TRUE)
is_DT = vapply_1b(mget(all_obj, envir=env), is.data.table)
Copy link
Member

@mattdowle mattdowle Nov 13, 2022

Choose a reason for hiding this comment

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

changing from get to mget here meant that inherits was changed from TRUE to FALSE because the defaults are different. But doesn't matter as the input is ls() in that env so it does exist there. Ok, got it.

@jangorecki jangorecki modified the milestones: 1.14.9, 1.15.0 Oct 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tables() fails: argument "..." is missing, with no default
3 participants