Change the default SQL preview magic comment

I'd like to use and recommend the Rstudio IDE for SQL file manipulation and previewing results. One thing that stops me from using it more often is that the preview isn't immediately accessible without changing the conn= definition.

Default:
-- !preview conn=DBI::dbConnect(RSQLite::SQLite())

Is there a way to change this for my own profile?
Is there a way to change it for all users of my Rstudio Server Pro?

Yes, both are possible! Create a file called query.sql with the contents you want, and put it in ~/.config/rstudio/templates (for you) or /etc/rstudio/templates (for everyone on your Pro server).

See https://docs.rstudio.com/ide/server-pro/r-sessions.html#default-document-templates for more detail.

1 Like

No, it should be mentioned in the admin guide but isn't. I've just updated it for the next version.

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

Perfect answer @jonathan!

Is the query.sql part of this documented anywhere else that I should have found?
Is there writing on other magic comments in Rstudio?