Open moodymudskipper opened 1 year ago
As part of #51
x <- data.frame(a=1:2)
x$b <- head(cars,2)
x$stringsAsFactors <- 3:4
x$c <- 5:6
x
data.frame(
a = 1:2,
c = 5:6
) |>
(`[[<-`)("b", value = head(cars, 2)) |>
(`[[<-`)("stringsAsFactors", value = 3:4) |>
(`[`)(c("a", "b", "stringsAsFactors", "c"))
Or
x <- data.frame(a=1:2)
x$stringsAsFactors <- 3:4
x$b <- 5:6
x
data.frame(
a = 1:2,
stringsAsFactors.1 = 3:4,
b = 5:6
) |>
setNames(c("a", "stringsAsFactors", "b"))
Maybe this idiom looks better, no replacement functions :
data.frame(
a = 1:2,
c = 5:6
) |>
within({
b <- head(cars, 2)
stringsAsFactors <- 3:4
}) |>
subset(select = c(a, b, stringsAsFactors, c))
This select =
is interesting, it's a bit like tidy selection, we can could compress things using col1:col2
or -col1
, but that's a lot of work for corner cases unless we find this idiom useful in more places.
We had this issue for #104
How do we create a tibble with a
.rows
column ? how do we create a data frame with astringsAsFactors
column ? Since they should be rare (if the constructors are well designed) that's probably ok to just fall back tostructure()
for those.We need in general a fall back system for corrupted objects and
structure()
should be the default and last fallback