Re: [Rd] FR: valid_regex() to test string validity as a regular expression

2023-10-11 Thread Michael Chirico via R-devel
perl = FALSE) : > invalid regular expression '(invalid', reason 'Missing ')'' > In addition: Warning message: > In grepl("(invalid", "subject", perl = FALSE) : > TRE pattern compilation error 'Missing ')''

Re: [Rd] FR: valid_regex() to test string validity as a regular expression

2023-10-10 Thread Michael Chirico via R-devel
ng" before any regex is actually executed. At a bare minimum this is a good place to return a classed warning (say invalid_regex_warning) to allow finer control than tryCatch(condition=). On Mon, Oct 9, 2023, 11:30 PM Tomas Kalibera wrote: > > On 10/10/23 01:57, Michael Chirico

[Rd] FR: valid_regex() to test string validity as a regular expression

2023-10-09 Thread Michael Chirico via R-devel
It will be useful to package authors trying to validate input which is supposed to be a valid regular expression. As near as I can tell, the only way we can do so now is to run any regex function and check for the warning and/or condition to bubble up: valid_regex <- function(str) { stopifnot(i

[Rd] Unclear provenance of message from S4

2023-08-14 Thread Michael Chirico via R-devel
MRE to produce the message is the following: setClass("Foo") setOldClass("Bar") setAs("Bar", "Foo", \(x) x) # NOTE: arguments in definition for coerce changed from (x) to (from) In an interactive setting, that may be fine, but I first encountered this message in the install log of a package for w

Re: [Rd] Improving user-friendliness of S4 dispatch failure when mis-naming arguments?

2023-08-11 Thread Michael Chirico via R-devel
re(x = "double", y = "double"), \(x, y, ...) x + y) BaseGeneric(X = 1, Y = 2) # Error: unable to find an inherited method for function ‘BaseGeneric’ for signature ‘x="missing", y="missing"’ On Fri, Aug 11, 2023 at 2:26 AM Martin Maechler wrote: > > >

Re: [Rd] Improving user-friendliness of S4 dispatch failure when mis-naming arguments?

2023-08-10 Thread Michael Chirico via R-devel
cents that I think it would be very useful and > beneficial to improve S4 to surface that information as well. > > More information about the way that the dispatch failed would be of great > help in situations like the one Michael pointed out. > > ~G > > On Thu, A

Re: [Rd] Improving user-friendliness of S4 dispatch failure when mis-naming arguments?

2023-08-10 Thread Michael Chirico via R-devel
("conn", "statement")) > dbGetQuery(connection = NULL, query = NULL) > #> Error: Can't find method for generic `dbGetQuery(conn, statement)`: > #> - conn : MISSING > #> - statement: MISSING > > Hadley > > On Wed, Aug 9, 2023 at 10:02 PM Mi

[Rd] Improving user-friendliness of S4 dispatch failure when mis-naming arguments?

2023-08-09 Thread Michael Chirico via R-devel
I fielded a debugging request from a non-expert user today. At root was running the following: dbGetQuery(connection = conn, query = query) The problem is that they've named the arguments incorrectly -- it should have been [1]: dbGetQuery(conn = conn, statement = query) The problem is that the

Re: [Rd] tab-complete for non-syntactic names could attempt backtick-wrapping

2023-03-02 Thread Michael Chirico via R-devel
I personally wouldn't like using a string, and this comment makes me think it's against the r-core preference as well: https://bugs.r-project.org/show_bug.cgi?id=18429#c1 Thanks both for catching the sloppy mistake in vapply() :) Let's continue discussion on the bug/PR. On Thu, Mar 2, 2023 at 1

Re: [Rd] tab-complete for non-syntactic names could attempt backtick-wrapping

2023-03-01 Thread Michael Chirico via R-devel
Great suggestion! I've started a patch: https://bugs.r-project.org/show_bug.cgi?id=18479 On Wed, Mar 1, 2023 at 1:56 AM Ivan Krylov wrote: > > В Wed, 1 Mar 2023 01:36:02 -0800 > Michael Chirico via R-devel пишет: > > > +comps[non_syntactic] <- paste0("`",

[Rd] tab-complete for non-syntactic names could attempt backtick-wrapping

2023-03-01 Thread Michael Chirico via R-devel
Consider: x <- list(`a b` = 1) x$a (i.e., press the 'tab' key after typing 'x$a') The auto-complete mechanism will fill the buffer like so: x$a b This is not particularly helpful because this is now a syntax error. It seems to me there's a simple fix -- in utils:::specialCompletions(), we can

[Rd] FR: names= argument for load()

2023-02-28 Thread Michael Chirico via R-devel
I have three use cases in mind for an argument to load specifying which variables to load from the input 'file': 1. Avoid overwriting existing variables. ?load recommends using envir= or attach() to avoid overwrites. An argument like names= would allow even finer control to avoid collisions. 2. Av

Re: [Rd] Line-terminal \ in character consants -- missing from ?Quotes ?

2023-02-12 Thread Michael Chirico via R-devel
/github.com/r-devel/r-svn/blob/f55b24945d56e824f124638c596b99887441354a/src/main/gram.y#L2978-L3008 ('\n' is in the list of valid items after '\') I don't see any special handling for '\r', so there may be a gap in the R parser? Or I just don't understand w

[Rd] Line-terminal \ in character consants -- missing from ?Quotes ?

2023-02-11 Thread Michael Chirico via R-devel
I'm coming across some code that uses the fact the parser ignores a line-terminal '\', e.g. identical("\ ", "\n") # [1] TRUE x = "abc \ def" y = "abc \ndef" identical(x, y) # [1] TRUE However: identical("\\n", "\n") # [1] FALSE This appears to be undocumented behavior; the closest thing I see i

[Rd] Shouldn't "Loading" be "Attaching" when referring to library() calls?

2023-01-09 Thread Michael Chirico via R-devel
require() and library() both emit this message immediately before running library(): "Loading required package: %s" https://github.com/r-devel/r-svn/blob/4198a2941b702d965bb2374c2b908f48c369f40a/src/library/base/R/library.R#L967-L968 https://github.com/r-devel/r-svn/blob/4198a2941b702d965bb2374c

Re: [Rd] .onLoad, packageStartupMessage, and R CMD check

2021-11-05 Thread Michael Chirico via R-devel
pushing > back against your linter were using messages from .onLoad for... > > Best, > ~G > > > > On Thu, Nov 4, 2021 at 12:37 PM Duncan Murdoch > wrote: >> >> On 04/11/2021 2:50 p.m., Michael Chirico via R-devel wrote: >> > I wrote a linter to

[Rd] .onLoad, packageStartupMessage, and R CMD check

2021-11-04 Thread Michael Chirico via R-devel
I wrote a linter to stop users from using packageStartupMessage() in their .onLoad() hook because of the R CMD check warning it triggers: https://github.com/wch/r-source/blob/8b6625e39cd62424dc23399dade37f20fa8afa91/src/library/tools/R/QC.R#L5167 However, this received some pushback which I ultim

[Rd] Should seq.Date() return double storage?

2021-09-07 Thread Michael Chirico via R-devel
today <- Sys.Date() typeof(today) # [1] "double" typeof(seq(today, by=1, length.out=2)) # [1] "integer" Clearly minor as it doesn't seem to have come up before (e.g. coercion to numeric will happen automatically whenever fractional dates are needed); I only noticed because of a test using identica