-
Notifications
You must be signed in to change notification settings - Fork 977
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
Closes #2887 -- adds a typo checker to i for convenience #2891
Conversation
man/chmatch.Rd
Outdated
@@ -41,7 +41,8 @@ chgroup(x) | |||
|
|||
# N is set small here (1e5) because CRAN runs all examples and tests every night, to catch | |||
# any problems early as R itself changes and other packages run. | |||
# The comments here apply when N has been changed to 1e8 and were run on 2018-05-13 with R 3.5.0 and data.table 1.11.2. | |||
# The comments here apply when N has been changed to 1e8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is irrelevant to this PR, but I was getting a NOTE
from R CMD check
about an overfull line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but better wait with it till 1.12.0
@MichaelChirico maybe some more test for column names including spaces and special characters?
agree, we should keep it as experimental in dev for a while.
…On Fri, Jun 15, 2018, 12:37 AM Jan Gorecki ***@***.***> wrote:
***@***.**** approved this pull request.
LGTM, but better wait with it till 1.12.0
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#2891 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHQQdYaw3oDaf9YFW6v1Gj7cO7fYOS3rks5t8pFEgaJpZM4UFjNr>
.
|
R/data.table.R
Outdated
if (length(found)) { | ||
stop("Object '", used, "' not found. Perhaps you ", | ||
sprintf("intended one of: [%s]", | ||
paste(found, collapse = ', '))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 suggestions:
- Add a special case for
length(found) == 1
("one of ..." seems awkward for 1 item). - Limit the number of columns suggested to 3 or 4 (in theory your DT can have 1000s of columns, similarly named, and all of them might be found by
agrep
).
R/data.table.R
Outdated
paste(found, collapse = ', '))) | ||
} else { | ||
stop("Object '", used, "' not found among: ", | ||
sprintf("[%s]", paste(ref, collapse = ', '))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly here ref
can have an enormous size.
a very reasonable case for this is columns like V1,...,Vn or in a wide
table like income00, income01, ..., income18.
I thought of putting in a limit to prevent error explosion, but R does that
itself
https://stackoverflow.com/a/50387968/3576984
OTOH I guess the user should get the point... if they put in Vx and are
matched to V1,...,V99, seeing "V1,V2,V3,..." should be sufficient.
…On Fri, Jun 15, 2018, 7:54 AM Pasha Stetsenko ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In R/data.table.R
<#2891 (comment)>
:
> @@ -200,6 +200,21 @@ replace_dot_alias <- function(e) {
x
}
+.checkTypos = function(err, ref) {
+ if (grepl('object.*not found', err$message)) {
+ used = gsub(".*object '([^']+)'.*", "\\1", err$message)
+ found = agrep(used, ref, value = TRUE, ignore.case = TRUE, fixed = TRUE)
+ if (length(found)) {
+ stop("Object '", used, "' not found. Perhaps you ",
+ sprintf("intended one of: [%s]",
+ paste(found, collapse = ', ')))
2 suggestions:
1. Add a special case for length(found) == 1 ("one of ..." seems
awkward for 1 item).
2. Limit the number of columns suggested to 3 or 4 (in theory your DT
can have 1000s of columns, similarly named, and all of them might be found
by agrep).
------------------------------
In R/data.table.R
<#2891 (comment)>
:
> @@ -200,6 +200,21 @@ replace_dot_alias <- function(e) {
x
}
+.checkTypos = function(err, ref) {
+ if (grepl('object.*not found', err$message)) {
+ used = gsub(".*object '([^']+)'.*", "\\1", err$message)
+ found = agrep(used, ref, value = TRUE, ignore.case = TRUE, fixed = TRUE)
+ if (length(found)) {
+ stop("Object '", used, "' not found. Perhaps you ",
+ sprintf("intended one of: [%s]",
+ paste(found, collapse = ', ')))
+ } else {
+ stop("Object '", used, "' not found among: ",
+ sprintf("[%s]", paste(ref, collapse = ', ')))
Similarly here ref can have an enormous size.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#2891 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHQQddH-PUHJDAskuxJU__V9wCARvmz6ks5t8ve4gaJpZM4UFjNr>
.
|
…just leaving R to chop very long message
awesome, thanks! |
@MichaelChirico Did you benchmark to see if this slowed things down? It's an (expensive) We don't mind too much about call overhead normally, but |
let me investigate...
…On Fri, Sep 7, 2018, 7:43 AM Matt Dowle ***@***.***> wrote:
@MichaelChirico <https://github.com/MichaelChirico> Did you benchmark to
see if this slowed things down? It's an (expensive) tryCatch on most
[.data.table calls that contains i iiuc? Is there a way to avoid tryCatch?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2891 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHQQdd9FNqnmwfHkfOPospGIVeMeBzmnks5uYbM6gaJpZM4UFjNr>
.
|
Possibly tryCatch can be moved inside |
Pretty rudimentary, just to get things started.
A few points for discussion/improvement:
.GlobalEnv
for now, but I left.checkTypos
flexible enough that it should be easy to expand this (by either sendingc(names(x), ls(envir = .GlobalEnv))
as theref
argument, or by splitting intoref_x
andref_global_env
to allow the error to distinguish between objects found in the scope ofx
vs. parent scope)i
. If we think it's worth it, could add similar code in other places like here or even herej
orby
for now.agrep
might be able to suggest different defaults for thecost
value(s).