Kurt Hornik
2025-Jan-23 10:16 UTC
[Rd] Depends: R (>= 4.1) for packages that use |> and \(...)
>>>>> Ivan Krylov via R-devel writes:Thanks. I am already looking handling the 4.2.0 placeholder syntax, but likely will need to refactor the code I added yesterday. The "experimental" 4.3.0 extra placeholder feature looks like a lot of effort: ideally there would be a simpler way. I'll ask on R Core. My guess would be that the new syntax is particularly prominently used in examples: if so, it would be good to also have coverage for this. Best -k> Many thanks to Henrik for remembering the report in Bugzilla and to > Kurt for implementing the change and finding out the true number of > affected packages.> On Wed, 22 Jan 2025 15:34:41 -0500 > Ian Farm <ian.farm at maine.edu> wrote:>> Would packages using the underscore placeholder with the native pipe >> need to also depend on R >= 4.2.0?> That's a good find! For the R >= 4.2 syntax, we only need to check for > getParseData(...)$token %in% 'PLACEHOLDER'. The R >= 4.3 syntax feature > is harder to test for:>>> As an experimental feature the placeholder _ can now also be used in >>> the rhs of a forward pipe |> expression as the first argument in an >>> extraction call, such as _$coef. More generally, it can be used as >>> the head of a chain of extractions, such as _$coef[[2]].> I think it might be possible to parse(text = paste('PLACEHOLDER |>', > grandparent_expression)) and then look at the top-level function in the > call, but that feels quite fragile:> x <- utils::getParseData(parse(f, keep.source = TRUE)) > i <- x$token %in% "PLACEHOLDER" > pi <- x[i, "parent"] > ppi <- x[x$id %in% pi, "parent"] > placeholder_expressions <- utils::getParseText(x, ppi) > extractor_used <- vapply(placeholder_expressions, function(src) { > toplevel <- parse(text = paste("PLACEHOLDER |> ", src))[[1]][[1]] > identical(toplevel, quote(`$`)) || > identical(toplevel, quote(`[`)) || > identical(toplevel, quote(`[[`)) > }, FALSE)> Alternatively, we may find the first child of the grandparent of the > placeholder. If it's the placeholder expression, then the pipe must be > of the form ...|> _..., which is the R >= 4.3 syntax:> x <- utils::getParseData(parse(f, keep.source = TRUE)) > i <- x$token %in% "PLACEHOLDER" > vapply(which(i), function(i) { > pi <- x[i, "parent"] > ppi <- x[x$id %in% pi, "parent"] > cppi <- x[x$parent %in% ppi, "id"] > min(cppi) == pi > }, FALSE)> -- > Best regards, > Ivan> ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel
Kurt Hornik
2025-Jan-25 16:26 UTC
[Rd] Depends: R (>= 4.1) for packages that use |> and \(...)
>>>>> Kurt Hornik writes:Thanks again. All added now with c87633. Best -k>>>>> Ivan Krylov via R-devel writes: > Thanks. I am already looking handling the 4.2.0 placeholder syntax, but > likely will need to refactor the code I added yesterday.> The "experimental" 4.3.0 extra placeholder feature looks like a lot of > effort: ideally there would be a simpler way. I'll ask on R Core.> My guess would be that the new syntax is particularly prominently used > in examples: if so, it would be good to also have coverage for this.> Best > -k>> Many thanks to Henrik for remembering the report in Bugzilla and to >> Kurt for implementing the change and finding out the true number of >> affected packages.>> On Wed, 22 Jan 2025 15:34:41 -0500 >> Ian Farm <ian.farm at maine.edu> wrote:>>> Would packages using the underscore placeholder with the native pipe >>> need to also depend on R >= 4.2.0?>> That's a good find! For the R >= 4.2 syntax, we only need to check for >> getParseData(...)$token %in% 'PLACEHOLDER'. The R >= 4.3 syntax feature >> is harder to test for:>>>> As an experimental feature the placeholder _ can now also be used in >>>> the rhs of a forward pipe |> expression as the first argument in an >>>> extraction call, such as _$coef. More generally, it can be used as >>>> the head of a chain of extractions, such as _$coef[[2]].>> I think it might be possible to parse(text = paste('PLACEHOLDER |>', >> grandparent_expression)) and then look at the top-level function in the >> call, but that feels quite fragile:>> x <- utils::getParseData(parse(f, keep.source = TRUE)) >> i <- x$token %in% "PLACEHOLDER" >> pi <- x[i, "parent"] >> ppi <- x[x$id %in% pi, "parent"] >> placeholder_expressions <- utils::getParseText(x, ppi) >> extractor_used <- vapply(placeholder_expressions, function(src) { >> toplevel <- parse(text = paste("PLACEHOLDER |> ", src))[[1]][[1]] >> identical(toplevel, quote(`$`)) || >> identical(toplevel, quote(`[`)) || >> identical(toplevel, quote(`[[`)) >> }, FALSE)>> Alternatively, we may find the first child of the grandparent of the >> placeholder. If it's the placeholder expression, then the pipe must be >> of the form ...|> _..., which is the R >= 4.3 syntax:>> x <- utils::getParseData(parse(f, keep.source = TRUE)) >> i <- x$token %in% "PLACEHOLDER" >> vapply(which(i), function(i) { >> pi <- x[i, "parent"] >> ppi <- x[x$id %in% pi, "parent"] >> cppi <- x[x$parent %in% ppi, "id"] >> min(cppi) == pi >> }, FALSE)>> -- >> Best regards, >> Ivan>> ______________________________________________ >> R-devel at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-devel
Ivan Krylov
2025-Feb-06 15:18 UTC
[Rd] Depends: R (>= 4.1) for packages that use |> and \(...)
On Thu, 23 Jan 2025 11:16:48 +0100 Kurt Hornik <Kurt.Hornik at wu.ac.at> wrote:> My guess would be that the new syntax is particularly prominently used > in examples: if so, it would be good to also have coverage for this.In today's CRAN snapshot, there turned out to be 198 packages that use 4.1 syntax in examples but not in code, 5 packages that use 4.2 syntax in examples but 4.1 in the code, and 3 packages that use 4.2 syntax in examples but not the code. This may be slightly imprecise because I don't have some of the Rd macro packages installed and run Rd2ex(stages=NULL) on manually-parsed Rd files without installing the packages. Attaching a patch that checks the syntax used in Rd examples at the same time as the main R code, not necessarily the best way to perform this check. Is it perhaps worth separating R/* checks from man/*.Rd checks? Should R CMD check try to reuse the Rd database from the installed copy of the package? -- Best regards, Ivan -------------- next part -------------- A non-text attachment was scrubbed... Name: check_R_syntax_in_examples.patch Type: text/x-patch Size: 4000 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20250206/9fd89fa8/attachment.bin>