Skip to content

Keep leading whitespace 🙏  #714

@MayaGans

Description

@MayaGans

Hey Rich and co!

I created a data frame with intentional leading whitespace and it looks like converting to a gt object automatically removes this?

the_data <- data.frame(
  spacey = c("No space", "    Four Spaces", "    Four Spaces")
)

# my spaces are gone :(
the_data(gt)

I attempted to get clever and replace the whitespaces with &nbsp

encode_whitespace <- function(strg) {
  gsub(" ", '&nbsp;', strg)
}

the_data %>%
  mutate(spacey = encode_whitespace(spacey)) %>%
  gt()

But 🤦 this is interpreted as literal text womp womp. Hoping you have a better idea! 🤞

PS as a more general feature request: this might be too opinionated but just throwing it out there.... it would align with my mental model for the default behavior of gt() to keep any user created whitespace before generating the table. In my mind this puts the onus on the user to clean up rather than have gt do it for us? Just a thought!

Oh and thanks again for this package it's the GOAT table generator ❤️

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions