[R-pkg-devel] Native pipe in package examples
Henrik Bengtsson
henr|k@bengt@@on @end|ng |rom gm@||@com
Thu Jan 25 18:44:26 CET 2024
On Thu, Jan 25, 2024 at 9:23 AM Berwin A Turlach
<berwin.turlach using gmail.com> wrote:
>
> G'day Duncon,
>
> On Thu, 25 Jan 2024 11:27:50 -0500
> Duncan Murdoch <murdoch.duncan using gmail.com> wrote:
>
> > On 25/01/2024 11:18 a.m., Henrik Bengtsson wrote:
> [...]
> > I think you're right that syntax errors in help page examples will be
> > installable, but I don't think there's a way to make them pass "R CMD
> > check" other than wrapping them in \dontrun{}, and I don't know a way
> > to do that conditional on the R version.
>
> I remember vaguely that 'S Programming' was discussing some nifty
> tricks to deal with differences between S and R, and how to write code
> that would work with either. If memory serves correctly, those
> tricks depended on whether a macro called using_S (using_R?) was
> defined. Not sure if the same tricks could be used to distinguish
> between different versions of R.
>
> But you could always code your example (not tested :-) ) along lines
> similar to:
>
> if( with(version, all(as.numeric(c(major, minor)) >= c(4, 1))) ){
> ## code that uses native pipe
> }else{
> cat("You have to upgrade to R >= 4.1.0 to run this example\n")
> }
That will unfortunately not work in this case, because |> is part of
the new *syntax* that was introduced in R 4.1.0. Older versions of R
simply doesn't understand how to *parse* those two symbols next to
each other, e.g.
{R 4.1.0}> parse(text = "1:3 |> sum()")
expression(1:3 |> sum())
{R 4.0.5}> parse(text = "1:3 |> sum()")
Error in parse(text = "1:3 |> sum()") : <text>:1:6: unexpected '>'
1: 1:3 |>
^
In order for R to execute some code, it needs to be able to parse it
first. Only then, it can execute it. So, here, we're not even getting
past the parsing phase.
/Henrik
>
>
> > I would say that a package that doesn't pass "R CMD check" without
> > errors shouldn't be trusted.
>
> Given the number of packages on CRAN and Murphy's law (or equivalents),
> I would say that there are packages that do pass "R CMD check" without
> errors but shouldn't be trusted, own packages not excluded. :)
>
> Cheers,
>
> Berwin
More information about the R-package-devel
mailing list