Leave trailing whitespace

Is there a setting in RStudio v1.3.911 to keep trailing whitespace in multi-line strings after saving?

For example, after saving a .R file, the space after SELECT is removed, breaking the query.

glue::glue("SELECT 
city, state...")

To remedy the issue, I can add \\ after the space, but it makes the query print on one line.

1 Like

Interesting problem; perhaps platform related.

As a stopgap you can consider opening whitespace - I like my queries aligned, with the city 3 spaces from SELECT, which would align with FROM etc... Opening whitespace is kept even when trailing is dropped.

Obviously not a solution, but perhaps a workaround?

It looks like glue() has a trim = argument whose default value is TRUE -- does it do what you want if you set it to FALSE?

1 Like

If you put the space character at the beginning of the second line you can "see" that it's worked:

glue::glue("SELECT 
 city, state...", .trim=FALSE)

HTH

In Project Options > Code Editing, there's a Strip trailing horizontal whitespace when saving setting that caused the issue. That setting is under Global Options too, Global Options > Code > Saving, and it is not selected. When I create a new project via usethis::create_project(), the global option is ignored and it is selected in the new project.

capture|429x170

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.