Re: [R-pkg-devel] Native pipe in package examples

2024-01-27 Thread Jon Harmon
See
https://github.com/r-lib/httr2/blob/main/configure
and
https://github.com/r-lib/httr2/blob/main/tools%2Fexamples.R

(and https://r-pkgs.org/misc.html#sec-misc-tools if you're not sure what
you're looking at).

They use a build-time script to change the examples. It looks like it just
puts a header on them saying they won't run (and stops them from executing
in checks, I think?). It'd be interesting to use that trick to actually
change the code, but probably more trouble than it's worth.

[[alternative HTML version deleted]]

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


Re: [R-pkg-devel] Native pipe in package examples

2024-01-26 Thread Duncan Murdoch

On 25/01/2024 12:38 p.m., Henrik Bengtsson wrote:

On Thu, Jan 25, 2024 at 8:27 AM Duncan Murdoch  wrote:


On 25/01/2024 11:18 a.m., Henrik Bengtsson wrote:

On Thu, Jan 25, 2024 at 7:48 AM Duncan Murdoch  wrote:


On 25/01/2024 10:27 a.m., Josiah Parry wrote:

Hey all,

I've encountered use of the native pipe operator in the examples for
'httr2' e.g.

request("http://example.com;) |> req_dry_run()


Since r-oldrel (according to rversions::r_oldrel()) is now 4.2.3, can the
native pipe be used in example code?

I do notice that the package httr2 requires R >= 3.6.0 which implies that
the code itself does not use the native pipe, but the examples do.


I think that the package should state it requires R (>= 4.1.0), since
that code won't work in earlier versions.

I believe it's a syntax error before 4.1.0, but don't have a copy handy
to test.


Yes, support for the |> syntax was introduced in R 4.1.0;

$ Rscript --vanilla -e "getRversion()" -e "1:10 |> sum()"
[1] ‘4.0.5’
Error: unexpected '>' in "1:10 |>"
Execution halted

$ Rscript --vanilla -e "getRversion()" -e "1:10 |> sum()"
[1] ‘4.1.0’
[1] 55


That means the package won't pass R CMD check in those old
versions.  If it wasn't a syntax error, just a case of using a new
feature, then I think it would be fine to put in a run-time test of the
R version to skip code that won't run properly.


There's also the distinction of package code versus code in
documentation. If it's only example code in help pages that use the
native pipe, but the code in R/*.R does not, then the package will
still install and work with R (< 4.1.0).  The only thing that won't
work is when the user tries to run the code in the documented
examples.  I'd argue that it's okay to specify, say, R (>= 3.6.0) in
such an example.  It allows users with older versions to still use the
package, while already now migrating the documentation to use newer
syntax.


Is there a way to do that so that R will pay attention, or do you mean
just saying it in a comment?


As a "comment".



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 think

$ R CMD check --no-examples --no-vignettes ...

would check everything else but examples and vignettes.



I would say that a package that doesn't pass "R CMD check" without
errors shouldn't be trusted.


Somewhat agree, but we still get some "trust" from the fact that the
package passes R CMD check --as-cran on R (>= 4.1.0).  Also, if the
maintainer documents something like "On R (> 4.1.0), the package
passes 'R CMD check --no-examples ...'; we use R (>= 4.1.0)-specific
syntax in some of the help-age examples", then there's additional
"trust" in it's working there.  But, yes, there's less "trust" here,
but I think it's okay for maintainers to declare "R (>= 3.6.0)" to be
backward compatible. Another way to put it, it would be extreme to
require "R (>= 4.1.0)" just because of a single "1:3 |> sum()" in some
example code.

/Henrik

PS. Personally, I'd skip the use of |> in examples to avoid these concerns.


I think we agree.  If I was determined to support 3.6.0 users, I'd 
recode that example as


  req_dry_run(request("http://example.com;))

  # It is convenient to use the native pipe |> in R 4.1.0 or greater:

  #   request("http://example.com;) |> req_dry_run()

  # ... or the magrittr pipe if available:

  #   request("http://example.com;) %>% req_dry_run()

Duncan Murdoch

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


Re: [R-pkg-devel] Native pipe in package examples

2024-01-26 Thread Serguei Sokol

Le 26/01/2024 à 10:44, Serguei Sokol a écrit :

Le 26/01/2024 à 10:31, Serguei Sokol a écrit :

Le 25/01/2024 à 19:04, Berwin A Turlach a écrit :

On Thu, 25 Jan 2024 09:44:26 -0800
Henrik Bengtsson  wrote:


On Thu, Jan 25, 2024 at 9:23 AM Berwin A Turlach
 wrote:


G'day Duncon,


Uups, apologies for the misspelling of your name Duncan. Fingers were
too fast. :)

[...]

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()") : :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.


Well, not withstanding 'fortune(181)', you could code it as:

if( with(version, all(as.numeric(c(major, minor)) >= c(4, 1))) ){
    cat(eval(parse(text="1:3 |> sum()")), "\n")
}else{
   cat("You have to upgrade to R >= 4.1.0 to run this example\n")
}

By nitpicking a little bit, this test won't work for v5.0 as minor 
"0" is less then "1". There are a more canonical ways to test the 
version and send a message (or a 'warning()'):


if (getVersion() >= "4.1") {

Oops, it won't work for v10.0. Better would be:

if (utils::compareVersion(getVersion(), "4.1.0") >= 0) {
Sorry for annoyance (not a good day for sending messages), obviously it 
should be 'getRversion()'


Best,
Serguei.



Best,
Serguei.


cat(eval(parse(text="1:3 |> sum()")), "\n")
} else {
   message("You have to upgrade to R >= 4.1.0 to run this example")
}

Best,
Serguei.




__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


Re: [R-pkg-devel] Native pipe in package examples

2024-01-26 Thread Serguei Sokol

Le 26/01/2024 à 10:31, Serguei Sokol a écrit :

Le 25/01/2024 à 19:04, Berwin A Turlach a écrit :

On Thu, 25 Jan 2024 09:44:26 -0800
Henrik Bengtsson  wrote:


On Thu, Jan 25, 2024 at 9:23 AM Berwin A Turlach
 wrote:


G'day Duncon,


Uups, apologies for the misspelling of your name Duncan. Fingers were
too fast. :)

[...]

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()") : :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.


Well, not withstanding 'fortune(181)', you could code it as:

if( with(version, all(as.numeric(c(major, minor)) >= c(4, 1))) ){
    cat(eval(parse(text="1:3 |> sum()")), "\n")
}else{
   cat("You have to upgrade to R >= 4.1.0 to run this example\n")
}

By nitpicking a little bit, this test won't work for v5.0 as minor "0" 
is less then "1". There are a more canonical ways to test the version 
and send a message (or a 'warning()'):


if (getVersion() >= "4.1") {

Oops, it won't work for v10.0. Better would be:

if (utils::compareVersion(getVersion(), "4.1.0") >= 0) {

Best,
Serguei.


cat(eval(parse(text="1:3 |> sum()")), "\n")
} else {
   message("You have to upgrade to R >= 4.1.0 to run this example")
}

Best,
Serguei.


__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


Re: [R-pkg-devel] Native pipe in package examples

2024-01-26 Thread Serguei Sokol

Le 25/01/2024 à 19:04, Berwin A Turlach a écrit :

On Thu, 25 Jan 2024 09:44:26 -0800
Henrik Bengtsson  wrote:


On Thu, Jan 25, 2024 at 9:23 AM Berwin A Turlach
 wrote:


G'day Duncon,


Uups, apologies for the misspelling of your name Duncan.  Fingers were
too fast. :)

[...]

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()") : :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.


Well, not withstanding 'fortune(181)', you could code it as:

if( with(version, all(as.numeric(c(major, minor)) >= c(4, 1))) ){
cat(eval(parse(text="1:3 |> sum()")), "\n")
}else{
   cat("You have to upgrade to R >= 4.1.0 to run this example\n")
}

By nitpicking a little bit, this test won't work for v5.0 as minor "0" 
is less then "1". There are a more canonical ways to test the version 
and send a message (or a 'warning()'):


if (getVersion() >= "4.1") {
   cat(eval(parse(text="1:3 |> sum()")), "\n")
} else {
   message("You have to upgrade to R >= 4.1.0 to run this example")
}

Best,
Serguei.

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


Re: [R-pkg-devel] Native pipe in package examples

2024-01-25 Thread Berwin A Turlach
On Thu, 25 Jan 2024 09:44:26 -0800
Henrik Bengtsson  wrote:

> On Thu, Jan 25, 2024 at 9:23 AM Berwin A Turlach
>  wrote:
> >
> > G'day Duncon,

Uups, apologies for the misspelling of your name Duncan.  Fingers were
too fast. :)

[...]
> > 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()") : :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.

Well, not withstanding 'fortune(181)', you could code it as:

if( with(version, all(as.numeric(c(major, minor)) >= c(4, 1))) ){
   cat(eval(parse(text="1:3 |> sum()")), "\n")
}else{
  cat("You have to upgrade to R >= 4.1.0 to run this example\n")
}  


Admittedly, it would be easier to say "Depends: R (>= 4.1.0)" in the
DESCRIPTION file. :)

Cheers,

Berwin

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


Re: [R-pkg-devel] Native pipe in package examples

2024-01-25 Thread Henrik Bengtsson
On Thu, Jan 25, 2024 at 9:23 AM Berwin A Turlach
 wrote:
>
> G'day Duncon,
>
> On Thu, 25 Jan 2024 11:27:50 -0500
> Duncan Murdoch  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()") : :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

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


Re: [R-pkg-devel] Native pipe in package examples

2024-01-25 Thread Henrik Bengtsson
On Thu, Jan 25, 2024 at 8:27 AM Duncan Murdoch  wrote:
>
> On 25/01/2024 11:18 a.m., Henrik Bengtsson wrote:
> > On Thu, Jan 25, 2024 at 7:48 AM Duncan Murdoch  
> > wrote:
> >>
> >> On 25/01/2024 10:27 a.m., Josiah Parry wrote:
> >>> Hey all,
> >>>
> >>> I've encountered use of the native pipe operator in the examples for
> >>> 'httr2' e.g.
> >>>
> >>> request("http://example.com;) |> req_dry_run()
> >>>
> >>>
> >>> Since r-oldrel (according to rversions::r_oldrel()) is now 4.2.3, can the
> >>> native pipe be used in example code?
> >>>
> >>> I do notice that the package httr2 requires R >= 3.6.0 which implies that
> >>> the code itself does not use the native pipe, but the examples do.
> >>
> >> I think that the package should state it requires R (>= 4.1.0), since
> >> that code won't work in earlier versions.
> >>
> >> I believe it's a syntax error before 4.1.0, but don't have a copy handy
> >> to test.
> >
> > Yes, support for the |> syntax was introduced in R 4.1.0;
> >
> > $ Rscript --vanilla -e "getRversion()" -e "1:10 |> sum()"
> > [1] ‘4.0.5’
> > Error: unexpected '>' in "1:10 |>"
> > Execution halted
> >
> > $ Rscript --vanilla -e "getRversion()" -e "1:10 |> sum()"
> > [1] ‘4.1.0’
> > [1] 55
> >
> >> That means the package won't pass R CMD check in those old
> >> versions.  If it wasn't a syntax error, just a case of using a new
> >> feature, then I think it would be fine to put in a run-time test of the
> >> R version to skip code that won't run properly.
> >
> > There's also the distinction of package code versus code in
> > documentation. If it's only example code in help pages that use the
> > native pipe, but the code in R/*.R does not, then the package will
> > still install and work with R (< 4.1.0).  The only thing that won't
> > work is when the user tries to run the code in the documented
> > examples.  I'd argue that it's okay to specify, say, R (>= 3.6.0) in
> > such an example.  It allows users with older versions to still use the
> > package, while already now migrating the documentation to use newer
> > syntax.
>
> Is there a way to do that so that R will pay attention, or do you mean
> just saying it in a comment?

As a "comment".

>
> 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 think

$ R CMD check --no-examples --no-vignettes ...

would check everything else but examples and vignettes.

>
> I would say that a package that doesn't pass "R CMD check" without
> errors shouldn't be trusted.

Somewhat agree, but we still get some "trust" from the fact that the
package passes R CMD check --as-cran on R (>= 4.1.0).  Also, if the
maintainer documents something like "On R (> 4.1.0), the package
passes 'R CMD check --no-examples ...'; we use R (>= 4.1.0)-specific
syntax in some of the help-age examples", then there's additional
"trust" in it's working there.  But, yes, there's less "trust" here,
but I think it's okay for maintainers to declare "R (>= 3.6.0)" to be
backward compatible. Another way to put it, it would be extreme to
require "R (>= 4.1.0)" just because of a single "1:3 |> sum()" in some
example code.

/Henrik

PS. Personally, I'd skip the use of |> in examples to avoid these concerns.

>
> Duncan Murdoch

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


Re: [R-pkg-devel] Native pipe in package examples

2024-01-25 Thread Berwin A Turlach
G'day Duncon,

On Thu, 25 Jan 2024 11:27:50 -0500
Duncan Murdoch  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")
}


> 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

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


Re: [R-pkg-devel] Native pipe in package examples

2024-01-25 Thread Duncan Murdoch

On 25/01/2024 11:44 a.m., Josiah Parry wrote:
The package of course passes R CMD check otherwise it wouldn’t be on 
CRAN! (:


CRAN doesn't run checks using R 3.6.0.  The package claims it works 
there, and maybe it will, but it won't pass R CMD check.


Duncan Murdoch




Thank you Henrik! Good to know my intuition was correct. I’m glad we can 
start to use the new features of R in package documentation :)


On Thu, Jan 25, 2024 at 11:27 Duncan Murdoch > wrote:


On 25/01/2024 11:18 a.m., Henrik Bengtsson wrote:
 > On Thu, Jan 25, 2024 at 7:48 AM Duncan Murdoch
mailto:murdoch.dun...@gmail.com>> wrote:
 >>
 >> On 25/01/2024 10:27 a.m., Josiah Parry wrote:
 >>> Hey all,
 >>>
 >>> I've encountered use of the native pipe operator in the
examples for
 >>> 'httr2' e.g.
 >>>
 >>> request("http://example.com ") |> req_dry_run()
 >>>
 >>>
 >>> Since r-oldrel (according to rversions::r_oldrel()) is now
4.2.3, can the
 >>> native pipe be used in example code?
 >>>
 >>> I do notice that the package httr2 requires R >= 3.6.0 which
implies that
 >>> the code itself does not use the native pipe, but the examples do.
 >>
 >> I think that the package should state it requires R (>= 4.1.0),
since
 >> that code won't work in earlier versions.
 >>
 >> I believe it's a syntax error before 4.1.0, but don't have a
copy handy
 >> to test.
 >
 > Yes, support for the |> syntax was introduced in R 4.1.0;
 >
 > $ Rscript --vanilla -e "getRversion()" -e "1:10 |> sum()"
 > [1] ‘4.0.5’
 > Error: unexpected '>' in "1:10 |>"
 > Execution halted
 >
 > $ Rscript --vanilla -e "getRversion()" -e "1:10 |> sum()"
 > [1] ‘4.1.0’
 > [1] 55
 >
 >> That means the package won't pass R CMD check in those old
 >> versions.  If it wasn't a syntax error, just a case of using a new
 >> feature, then I think it would be fine to put in a run-time test
of the
 >> R version to skip code that won't run properly.
 >
 > There's also the distinction of package code versus code in
 > documentation. If it's only example code in help pages that use the
 > native pipe, but the code in R/*.R does not, then the package will
 > still install and work with R (< 4.1.0).  The only thing that won't
 > work is when the user tries to run the code in the documented
 > examples.  I'd argue that it's okay to specify, say, R (>= 3.6.0) in
 > such an example.  It allows users with older versions to still
use the
 > package, while already now migrating the documentation to use newer
 > syntax.

Is there a way to do that so that R will pay attention, or do you mean
just saying it in a comment?

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 would say that a package that doesn't pass "R CMD check" without
errors shouldn't be trusted.

Duncan Murdoch



__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


Re: [R-pkg-devel] Native pipe in package examples

2024-01-25 Thread Josiah Parry
The package of course passes R CMD check otherwise it wouldn’t be on CRAN!
(:

Thank you Henrik! Good to know my intuition was correct. I’m glad we can
start to use the new features of R in package documentation :)

On Thu, Jan 25, 2024 at 11:27 Duncan Murdoch 
wrote:

> On 25/01/2024 11:18 a.m., Henrik Bengtsson wrote:
> > On Thu, Jan 25, 2024 at 7:48 AM Duncan Murdoch 
> wrote:
> >>
> >> On 25/01/2024 10:27 a.m., Josiah Parry wrote:
> >>> Hey all,
> >>>
> >>> I've encountered use of the native pipe operator in the examples for
> >>> 'httr2' e.g.
> >>>
> >>> request("http://example.com;) |> req_dry_run()
> >>>
> >>>
> >>> Since r-oldrel (according to rversions::r_oldrel()) is now 4.2.3, can
> the
> >>> native pipe be used in example code?
> >>>
> >>> I do notice that the package httr2 requires R >= 3.6.0 which implies
> that
> >>> the code itself does not use the native pipe, but the examples do.
> >>
> >> I think that the package should state it requires R (>= 4.1.0), since
> >> that code won't work in earlier versions.
> >>
> >> I believe it's a syntax error before 4.1.0, but don't have a copy handy
> >> to test.
> >
> > Yes, support for the |> syntax was introduced in R 4.1.0;
> >
> > $ Rscript --vanilla -e "getRversion()" -e "1:10 |> sum()"
> > [1] ‘4.0.5’
> > Error: unexpected '>' in "1:10 |>"
> > Execution halted
> >
> > $ Rscript --vanilla -e "getRversion()" -e "1:10 |> sum()"
> > [1] ‘4.1.0’
> > [1] 55
> >
> >> That means the package won't pass R CMD check in those old
> >> versions.  If it wasn't a syntax error, just a case of using a new
> >> feature, then I think it would be fine to put in a run-time test of the
> >> R version to skip code that won't run properly.
> >
> > There's also the distinction of package code versus code in
> > documentation. If it's only example code in help pages that use the
> > native pipe, but the code in R/*.R does not, then the package will
> > still install and work with R (< 4.1.0).  The only thing that won't
> > work is when the user tries to run the code in the documented
> > examples.  I'd argue that it's okay to specify, say, R (>= 3.6.0) in
> > such an example.  It allows users with older versions to still use the
> > package, while already now migrating the documentation to use newer
> > syntax.
>
> Is there a way to do that so that R will pay attention, or do you mean
> just saying it in a comment?
>
> 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 would say that a package that doesn't pass "R CMD check" without
> errors shouldn't be trusted.
>
> Duncan Murdoch
>

[[alternative HTML version deleted]]

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


Re: [R-pkg-devel] Native pipe in package examples

2024-01-25 Thread Duncan Murdoch

On 25/01/2024 11:18 a.m., Henrik Bengtsson wrote:

On Thu, Jan 25, 2024 at 7:48 AM Duncan Murdoch  wrote:


On 25/01/2024 10:27 a.m., Josiah Parry wrote:

Hey all,

I've encountered use of the native pipe operator in the examples for
'httr2' e.g.

request("http://example.com;) |> req_dry_run()


Since r-oldrel (according to rversions::r_oldrel()) is now 4.2.3, can the
native pipe be used in example code?

I do notice that the package httr2 requires R >= 3.6.0 which implies that
the code itself does not use the native pipe, but the examples do.


I think that the package should state it requires R (>= 4.1.0), since
that code won't work in earlier versions.

I believe it's a syntax error before 4.1.0, but don't have a copy handy
to test.


Yes, support for the |> syntax was introduced in R 4.1.0;

$ Rscript --vanilla -e "getRversion()" -e "1:10 |> sum()"
[1] ‘4.0.5’
Error: unexpected '>' in "1:10 |>"
Execution halted

$ Rscript --vanilla -e "getRversion()" -e "1:10 |> sum()"
[1] ‘4.1.0’
[1] 55


That means the package won't pass R CMD check in those old
versions.  If it wasn't a syntax error, just a case of using a new
feature, then I think it would be fine to put in a run-time test of the
R version to skip code that won't run properly.


There's also the distinction of package code versus code in
documentation. If it's only example code in help pages that use the
native pipe, but the code in R/*.R does not, then the package will
still install and work with R (< 4.1.0).  The only thing that won't
work is when the user tries to run the code in the documented
examples.  I'd argue that it's okay to specify, say, R (>= 3.6.0) in
such an example.  It allows users with older versions to still use the
package, while already now migrating the documentation to use newer
syntax.


Is there a way to do that so that R will pay attention, or do you mean 
just saying it in a comment?


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 would say that a package that doesn't pass "R CMD check" without 
errors shouldn't be trusted.


Duncan Murdoch

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


Re: [R-pkg-devel] Native pipe in package examples

2024-01-25 Thread Henrik Bengtsson
On Thu, Jan 25, 2024 at 7:48 AM Duncan Murdoch  wrote:
>
> On 25/01/2024 10:27 a.m., Josiah Parry wrote:
> > Hey all,
> >
> > I've encountered use of the native pipe operator in the examples for
> > 'httr2' e.g.
> >
> > request("http://example.com;) |> req_dry_run()
> >
> >
> > Since r-oldrel (according to rversions::r_oldrel()) is now 4.2.3, can the
> > native pipe be used in example code?
> >
> > I do notice that the package httr2 requires R >= 3.6.0 which implies that
> > the code itself does not use the native pipe, but the examples do.
>
> I think that the package should state it requires R (>= 4.1.0), since
> that code won't work in earlier versions.
>
> I believe it's a syntax error before 4.1.0, but don't have a copy handy
> to test.

Yes, support for the |> syntax was introduced in R 4.1.0;

$ Rscript --vanilla -e "getRversion()" -e "1:10 |> sum()"
[1] ‘4.0.5’
Error: unexpected '>' in "1:10 |>"
Execution halted

$ Rscript --vanilla -e "getRversion()" -e "1:10 |> sum()"
[1] ‘4.1.0’
[1] 55

> That means the package won't pass R CMD check in those old
> versions.  If it wasn't a syntax error, just a case of using a new
> feature, then I think it would be fine to put in a run-time test of the
> R version to skip code that won't run properly.

There's also the distinction of package code versus code in
documentation. If it's only example code in help pages that use the
native pipe, but the code in R/*.R does not, then the package will
still install and work with R (< 4.1.0).  The only thing that won't
work is when the user tries to run the code in the documented
examples.  I'd argue that it's okay to specify, say, R (>= 3.6.0) in
such an example.  It allows users with older versions to still use the
package, while already now migrating the documentation to use newer
syntax.

/Henrik
>
> Duncan Murdoch
>
> __
> R-package-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


Re: [R-pkg-devel] Native pipe in package examples

2024-01-25 Thread Duncan Murdoch

On 25/01/2024 10:27 a.m., Josiah Parry wrote:

Hey all,

I've encountered use of the native pipe operator in the examples for
'httr2' e.g.

request("http://example.com;) |> req_dry_run()


Since r-oldrel (according to rversions::r_oldrel()) is now 4.2.3, can the
native pipe be used in example code?

I do notice that the package httr2 requires R >= 3.6.0 which implies that
the code itself does not use the native pipe, but the examples do.


I think that the package should state it requires R (>= 4.1.0), since 
that code won't work in earlier versions.


I believe it's a syntax error before 4.1.0, but don't have a copy handy 
to test.  That means the package won't pass R CMD check in those old 
versions.  If it wasn't a syntax error, just a case of using a new 
feature, then I think it would be fine to put in a run-time test of the 
R version to skip code that won't run properly.


Duncan Murdoch

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


[R-pkg-devel] Native pipe in package examples

2024-01-25 Thread Josiah Parry
Hey all,

I've encountered use of the native pipe operator in the examples for
'httr2' e.g.

request("http://example.com;) |> req_dry_run()


Since r-oldrel (according to rversions::r_oldrel()) is now 4.2.3, can the
native pipe be used in example code?

I do notice that the package httr2 requires R >= 3.6.0 which implies that
the code itself does not use the native pipe, but the examples do.

Is this an accurate summation?

Thanks!

[[alternative HTML version deleted]]

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel