Make RStudio default software for opening data files (CSV/json etc.)

On a Mac you'd right-click a .csv file and select Get Info. From there you can change what application you want to use to open a file. In Choose Application, you'll have to change the dropdown "Enable All Applications", and then you can select RStudio (step by step instructions here.

Windows setup here

However, the above would just open the csv as a text file in RStudio, it wouldn't automatically import it.

I think there are ways of doing this, but it depends more on your system setup than RStudio itself.

You could probably make a shell script that launches RStudio and passes a file into a script (e.g. read.csv("<-path to file here->") — not actual code, that's just the idea).

On a Mac (which is what I'm on), you can use an application called Alfred to do "open file actions"

I'm pretty sure you can do the same thing using Mac Automator workflows, where you're, in essence, saying "when I do this, open this application, and use the selected file as a variable in this script that I want to run"
https://www.makeuseof.com/tag/learn-mac-automator-handy-example-workflows/

re. launching RStudio projects from the command line see here

2 Likes