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

object elements named as argument names of the constructor #124

Open
moodymudskipper opened this issue Apr 2, 2023 · 4 comments
Open

object elements named as argument names of the constructor #124

moodymudskipper opened this issue Apr 2, 2023 · 4 comments
Milestone

Comments

@moodymudskipper
Copy link
Collaborator

We had this issue for #104

How do we create a tibble with a .rows column ? how do we create a data frame with a stringsAsFactors column ?
Since they should be rare (if the constructors are well designed) that's probably ok to just fall back to structure() for those.

We need in general a fall back system for corrupted objects and structure() should be the default and last fallback

@moodymudskipper
Copy link
Collaborator Author

As part of #51

@moodymudskipper moodymudskipper added this to the 0.2 milestone Apr 2, 2023
@moodymudskipper
Copy link
Collaborator Author

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"))

@moodymudskipper
Copy link
Collaborator Author

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

@moodymudskipper
Copy link
Collaborator Author

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.

@moodymudskipper moodymudskipper modified the milestones: 0.2, backlog Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant