Skip to content

Conversation

@dpastoor
Copy link

@dpastoor dpastoor commented Jun 20, 2025

This PR will enable formatting via taplo. I kept it simple and am just using the taplo defaults. In theory could expose many other settings.

Ultimately there is also the taplo cli if someone wants more customization and could pipe the generated toml against as well, so inclined to just keep this simple.

The particular case that we hit when generating extensive rproject.toml files is dependency arrays that are quite long. This allows nice formatting.

@dpastoor
Copy link
Author

For example:

  test_toml <- toml(
    a_long_array = c("a long array", "with enough values", "to test formatting", "that should be broken over multiple lines"),
    a_short_array = c("a short array", "that doesn't break" ),
  )
> test_toml
<Toml>
a_long_array = [
  "a long array",
  "with enough values",
  "to test formatting",
  "that should be broken over multiple lines",
]
a_short_array = ["a short array", "that doesn't break"]

compared to the previous behavior (or behavior from print(test_toml, format = FALSE)

<Toml>
a_long_array = ["a long array", "with enough values", "to test formatting", "that should be broken over multiple lines"]
a_short_array = ["a short array", "that doesn't break"]

@JosiahParry
Copy link
Collaborator

Thank you! I think the tests are definitely something should've been done a while ago....

I want to give this PR a once over in the near future but my immediate thoughts are roughly as such:

  • format = TRUE probably shouldn't be a boolean argument but instead a list (or its own function?)
  • I think that using a list to specify the Options should probably be used
    • we can use the serde feature to serialize a list into this struct (or have a custom TryFrom impl)

otherwise i think this is really good?!

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

Successfully merging this pull request may close these issues.

2 participants