I realize that this is technically a formatting rather than programming question, but it's inter-related to an understanding of both SQL and RStudio, so I feel it's still appropriate.
I have a script written in Microsoft SQL Server Management Studio that is very intricately formatted for ease of viewing. For example:
SELECT (
CASE WHEN Variable in (1,2)
THEN 1
ELSE 2
END
)
However, when I paste this into RStudio, it becomes something like:
SELECT (
CASE WHEN Variable in (1,2)
THEN 1
ELSE 2
END
)
It maintains a tab when preceded by an open parenthesis, but nothing else. I can manipulate the size of the tabs it does keep, but no matter what options I use in Tools>GlobalOptions>CodeEditing, I can't keep any other formatting. It doesn't look like a big deal from the above example, but my code consists of multiple nested queries and becomes very confusing without the formatting. Any advice is appreciated!
I finally figured this out after asking the question, but I thought other people might have the same question, so I want to share the answer.
There's another option within Tools>GlobalOptions>CodeEditing that says "Auto-indent code after paste" that is checked as default. Apparently, it strips all your formatting AND adds its own tabs. Unchecking it fixed the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With