[R-pkg-devel] Package broke with R 4.3.0

Iñaki Ucar |uc@r @end|ng |rom |edor@project@org
Tue Jun 27 18:55:04 CEST 2023


On Tue, 27 Jun 2023 at 18:45, Jeff Newmiller <jdnewmil using dcn.davis.ca.us> wrote:
>
> if (any(c( "alaska", "hawaii") %in% zoom)){}

Note that this changes behavior. If e.g. zoom is c("something",
"alaska"), the code above returns TRUE. Previous behavior was FALSE
(with a warning).

Iñaki

> On June 27, 2023 9:11:09 AM PDT, "Göran Broström" <gb using ehar.se> wrote:
> >
> >
> >Den 2023-06-27 kl. 17:17, skrev Göran Broström:
> >> If(zoom %in% c(“alaska”,  “hawaii”)…
> >
> >Wrong, maybe
> >
> >if (("alaska" %in% zoom) || ("hawaii" %in% zoom)){}
> >
> >
> >>
> >> Göran
> >>
> >>> 27 juni 2023 kl. 16:32 skrev arilamstein using gmail.com:
> >>>
> >>> It appears that my R package choroplethr broke due to this change in R
> >>> 4.3.0:
> >>>
> >>> CHANGES IN R 4.3.0:
> >>>
> >>> SIGNIFICANT USER-VISIBLE CHANGES:
> >>>
> >>> Calling && or || with LHS or (if evaluated) RHS of length greater than one
> >>> is now always an error, with a report of the form
> >>>
> >>> 'length = 4' in coercion to 'logical(1)'
> >>> Environment variable R_CHECK_LENGTH_1_LOGIC2 no longer has any effect.
> >>>
> >>> The specific line which broke is this:
> >>> https://github.com/arilamstein/choroplethr/blob/master/R/usa.R#L24
> >>>
> >>> The bug can be reproduced like this:
> >>>
> >>> zoom = c("arizona", "arkansas", "louisiana", "minnesota", "mississippi",
> >>>       "montana", "new mexico", "north dakota", "oklahoma", "pennsylvania",
> >>>       "tennessee", "virginia", "california", "delaware", "west virginia",
> >>>       "wisconsin", "wyoming", "alabama", "alaska", "florida", "idaho",
> >>>       "kansas", "maryland", "colorado", "new jersey", "north carolina",
> >>>       "south carolina", "washington", "vermont", "utah", "iowa",
> >>> "kentucky",
> >>>       "maine", "massachusetts", "connecticut", "michigan", "missouri",
> >>>       "nebraska", "nevada", "new hampshire", "new york", "ohio", "oregon",
> >>>       "rhode island", "south dakota", "district of columbia", "texas",
> >>>       "georgia", "hawaii", "illinois", "indiana")
> >>>
> >>> if (zoom == "alaska" || zoom == "hawaii") {}
> >>> Error in zoom == "alaska" || zoom == "hawaii" :
> >>>   'length = 51' in coercion to 'logical(1)'
> >>>
> >>> I have two questions:
> >>>
> >>> 1. Can someone explain why this change was introduced to the language?
> >>> 2. Can someone tell me if there is a preferred, idiomatic way to rewrite my
> >>> code?
> >>>
> >>> I came up with two solutions that work. The first checks whether zoom is of
> >>> length 1:
> >>>
> >>> if ((length(zoom) == 1) && (zoom %in% c("alaska", "hawaii"))) { }
> >>>
> >>> The second keeps the vector recycling, but then uses all to coerce the
> >>> vector to be a single value. In retrospect, I think I likely assumed that
> >>> this is what R < 4.3.0 was doing when the code worked. (But I wrote this
> >>> code many years ago, so I can't be sure!):
> >>>
> >>> if (all(zoom == "alaska") || all(zoom == "hawaii")) {}
> >>>
> >>> Thanks in advance.
> >>>
> >>> Ari
> >>>
> >>>     [[alternative HTML version deleted]]
> >>>
> >>> ______________________________________________
> >>> R-package-devel using r-project.org mailing list
> >>> https://stat.ethz.ch/mailman/listinfo/r-package-devel
> >>
> >> ______________________________________________
> >> R-package-devel using r-project.org mailing list
> >> https://stat.ethz.ch/mailman/listinfo/r-package-devel
> >
> >______________________________________________
> >R-package-devel using r-project.org mailing list
> >https://stat.ethz.ch/mailman/listinfo/r-package-devel
>
> --
> Sent from my phone. Please excuse my brevity.
>
> ______________________________________________
> R-package-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel



-- 
Iñaki Úcar



More information about the R-package-devel mailing list