Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update stability.Rmd with c.factor() changes #1876

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions vignettes/stability.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading