Skip to content

Commit

Permalink
Merge pull request #652 from cynkra/f-641-paste-3
Browse files Browse the repository at this point in the history
- `dm_paste()` output uses trailing commas in the `dm::dm()` and `tibble::tibble()` calls, and sorts column attributes by name, for better modularity (#641).
  • Loading branch information
krlmlr committed Oct 13, 2021
2 parents 72dbcd0 + 9943357 commit 410de24
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions R/paste.R
Expand Up @@ -209,6 +209,11 @@ df_paste <- function(x, tab) {
}

deparse_line <- function(x) {
attrs <- attributes(x)
# Workaround necessary for R < 3.5:
if (length(attrs) > 0) {
attributes(x) <- attrs[sort(names(attrs))]
}
x <- deparse(x, width.cutoff = 500, backtick = TRUE)
gsub(" *\n *", " ", x)
}
Expand Down
8 changes: 5 additions & 3 deletions tests/testthat/_snaps/paste.md
Expand Up @@ -12,7 +12,9 @@
Message <cliMessage>
a <- tibble::tibble(
)
dm::dm(a)
dm::dm(
a,

This comment has been minimized.

Copy link
@TSchiefer

TSchiefer Oct 14, 2021

Member
  1. comma is too much
  2. I would even say, that for 1 element no newline is needed (no strong opinion though)

This comment has been minimized.

Copy link
@krlmlr

krlmlr Oct 15, 2021

Author Collaborator

Also in response to 72dbcd0#r58013082 and one other comment:

The extra comma and the distribution over separate lines is a key feature here. When building data models, we want new tables and new column cause the least disruption to existing code. Do we need two flavors of dm_paste() output, one aesthetically pleasing, another one for minimal diffs?

This comment has been minimized.

Copy link
@TSchiefer

TSchiefer Oct 18, 2021

Member

Right, I clearly missed that! :) I like the idea of having both options. Maybe the behavior could change depending on if path is set?

)
Code
# baseline
dm_for_filter() %>% dm_paste()
Expand Down Expand Up @@ -190,7 +192,7 @@
distance = numeric(0),
hour = numeric(0),
minute = numeric(0),
time_hour = structure(numeric(0), tzone = "America/New_York", class = c("POSIXct", "POSIXt")),
time_hour = structure(numeric(0), class = c("POSIXct", "POSIXt"), tzone = "America/New_York"),
)
planes <- tibble::tibble(
tailnum = character(0),
Expand Down Expand Up @@ -218,7 +220,7 @@
precip = numeric(0),
pressure = numeric(0),
visib = numeric(0),
time_hour = structure(numeric(0), tzone = "America/New_York", class = c("POSIXct", "POSIXt")),
time_hour = structure(numeric(0), class = c("POSIXct", "POSIXt"), tzone = "America/New_York"),
)
dm::dm(
airlines,
Expand Down

0 comments on commit 410de24

Please sign in to comment.