Formatting SQL Queries using R/

I am working with the R programming language.

Suppose I have an SQL query that is functional (i.e. works and runs without errors), but the formatting very bad (i.e. spaces and indents are in the wrong places).

Is it possible to use R (i.e. either some library or create functions using grepl/gsub) so that the SQL query can be correctly formatted, and the output is a string version of the query with the correct formatting?

Ideally, I would be looking for something like this SQL Formatter & Beautifier Online, but that does not require an active internet connection or makes API calls to some foreign site:

I found out about the sqlparser library, but this requires Python running in the back. I am looking for something purely in R.

Can someone please suggest something in R? Is it possible to write a function which takes unformatted SQL code and using a series of looped ifelse statements (i.e. after seeing a special keyword, e.g. a new CTE, subquery, GROUP, CASE .... puts the next lines of SQL code on the next line with the correct indents)?

Does this help?