From 53d9ed08bb2ea7655c4178235e34450c60755908 Mon Sep 17 00:00:00 2001 From: TJ Mahr Date: Fri, 8 Sep 2023 13:11:29 -0500 Subject: [PATCH 1/3] update stability.Rmd with c.factor() changes Fixes problem described in #1742. --- vignettes/stability.Rmd | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/vignettes/stability.Rmd b/vignettes/stability.Rmd index d6cf480bb..71aa1db69 100644 --- a/vignettes/stability.Rmd +++ b/vignettes/stability.Rmd @@ -196,18 +196,17 @@ vec_c(Sys.Date(), factor("x"), "x") ### Factors -Combining two factors returns an integer vector: +Prior to 4.1.0 (May 2021), combining two factors returned an integer vector. The current behavior creates a new factor with a combination of factor levels, similar to `vec_c()`. ```{r} fa <- factor("a") fb <- factor("b") c(fa, fb) +c(fb, fa) ``` -(This is documented in `c()` but is still undesirable.) - -`vec_c()` returns a factor taking the union of the levels. This behaviour is motivated by pragmatics: there are many places in base R that automatically convert character vectors to factors, so enforcing stricter behaviour would be unnecessarily onerous. (This is backed up by experience with `dplyr::bind_rows()`, which is stricter and is a common source of user difficulty.) +`vec_c()` also returns a factor taking the union of the levels. This behaviour is motivated by pragmatics: there are many places in base R that automatically convert character vectors to factors, so enforcing stricter behaviour would be unnecessarily onerous. (This is backed up by experience with `dplyr::bind_rows()`, which is stricter and is a common source of user difficulty.) ```{r} vec_c(fa, fb) From 1e6738ac3ffdb2ba4f56cc5ef70db81d70eef677 Mon Sep 17 00:00:00 2001 From: TJ Mahr Date: Fri, 8 Sep 2023 13:14:19 -0500 Subject: [PATCH 2/3] Update README.Rmd --- README.Rmd | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.Rmd b/README.Rmd index a9c57b211..bbb12babb 100644 --- a/README.Rmd +++ b/README.Rmd @@ -74,9 +74,6 @@ str(vec_cast_common(FALSE, 1L, 2.5)) The original motivation for vctrs comes from two separate but related problems. The first problem is that `base::c()` has rather undesirable behaviour when you mix different S3 vectors: ```{r} -# combining factors makes integers -c(factor("a"), factor("b")) - # combining dates and date-times gives incorrect values; also, order matters dt <- as.Date("2020-01-01") dttm <- as.POSIXct(dt) From 976515a141b0efa029c75b20731e0cfdcc2ce95b Mon Sep 17 00:00:00 2001 From: TJ Mahr Date: Fri, 8 Sep 2023 13:14:55 -0500 Subject: [PATCH 3/3] Update README.md --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index 7e85255cd..f5d1edf71 100644 --- a/README.md +++ b/README.md @@ -86,10 +86,6 @@ problems. The first problem is that `base::c()` has rather undesirable behaviour when you mix different S3 vectors: ``` r -# combining factors makes integers -c(factor("a"), factor("b")) -#> [1] 1 1 - # combining dates and date-times gives incorrect values; also, order matters dt <- as.Date("2020-01-01") dttm <- as.POSIXct(dt)