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

Should long vectors be formatted with one element per line? #103

Open
etiennebacher opened this issue Dec 14, 2024 · 1 comment
Open

Should long vectors be formatted with one element per line? #103

etiennebacher opened this issue Dec 14, 2024 · 1 comment

Comments

@etiennebacher
Copy link

For long vectors of "simple values", expanding one value per line really is a bit too much. For instance, for this vector:

c(
  "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"
)

air formats it like:

c(
	"a",
	"b",
	"c",
	[...]
	"x",
	"y",
	"z"
)

while it would probably be better (in this particular case) to have:

c(
  "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", 
  "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"
)

I'm sure there are a ton of counter examples where having one element per line is actually better, but I just wanted to mention this case.

Note that this is particularly visible when formatting the output of dput(). This is what dput(mtcars) gives:

structure(list(mpg = c(21, 21, 22.8, 21.4, 18.7, 18.1, 14.3, 
24.4, 22.8, 19.2, 17.8, 16.4, 17.3, 15.2, 10.4, 10.4, 14.7, 32.4, 
30.4, 33.9, 21.5, 15.5, 15.2, 13.3, 19.2, 27.3, 26, 30.4, 15.8, 
    [...]
    2, 2, 4, 4, 3, 3, 3, 4, 4, 4, 1, 2, 1, 1, 2, 2, 4, 2, 1, 
    2, 2, 4, 6, 8, 2)), row.names = c("Mazda RX4", "Mazda RX4 Wag", 
"Datsun 710", "Hornet 4 Drive", "Hornet Sportabout", "Valiant", 
"Duster 360", "Merc 240D", "Merc 230", "Merc 280", "Merc 280C", 
"Merc 450SE", "Merc 450SL", "Merc 450SLC", "Cadillac Fleetwood", 
"Lincoln Continental", "Chrysler Imperial", "Fiat 128", "Honda Civic", 
"Toyota Corolla", "Toyota Corona", "Dodge Challenger", "AMC Javelin", 
"Camaro Z28", "Pontiac Firebird", "Fiat X1-9", "Porsche 914-2", 
"Lotus Europa", "Ford Pantera L", "Ferrari Dino", "Maserati Bora", 
"Volvo 142E"), class = "data.frame")

This is how styler formats it (61 lines):

structure(list(
  mpg = c(
    21, 21, 22.8, 21.4, 18.7, 18.1, 14.3,
    24.4, 22.8, 19.2, 17.8, 16.4, 17.3, 15.2, 10.4, 10.4, 14.7, 32.4,
    30.4, 33.9, 21.5, 15.5, 15.2, 13.3, 19.2, 27.3, 26, 30.4, 15.8,
    19.7, 15, 21.4
  ), cyl = c(
    6, 6, 4, 6, 8, 6, 8, 4, 4, 6, 6, 8,
    8, 8, 8, 8, 8, 4, 4, 4, 4, 8, 8, 8, 8, 4, 4, 4, 8, 6, 8, 4
  ),
  [...]
), row.names = c(
  "Mazda RX4", "Mazda RX4 Wag",
  "Datsun 710", "Hornet 4 Drive", "Hornet Sportabout", "Valiant",
  "Duster 360", "Merc 240D", "Merc 230", "Merc 280", "Merc 280C",
  "Merc 450SE", "Merc 450SL", "Merc 450SLC", "Cadillac Fleetwood",
  "Lincoln Continental", "Chrysler Imperial", "Fiat 128", "Honda Civic",
  "Toyota Corolla", "Toyota Corona", "Dodge Challenger", "AMC Javelin",
  "Camaro Z28", "Pontiac Firebird", "Fiat X1-9", "Porsche 914-2",
  "Lotus Europa", "Ford Pantera L", "Ferrari Dino", "Maserati Bora",
  "Volvo 142E"
), class = "data.frame")

And this is how air formats it (413 lines):

structure(
	list(
		mpg = c(
			21,
			21,
			22.8,
			21.4,
			18.7,
			[...]
		"Maserati Bora",
		"Volvo 142E"
	),
	class = "data.frame"
)
@lionel-
Copy link
Collaborator

lionel- commented Dec 16, 2024

We're considering special comments that would let you request specific layouts for a function call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants