rstudio / rstudio

RStudio is an integrated development environment (IDE) for R
https://posit.co/products/open-source/rstudio/
Other
4.67k stars 1.09k forks source link

Allowing the user to start a "clean" portable local RStudio, without reading any settings from the user's appdata directory #14445

Open adrianolszewski opened 6 months ago

adrianolszewski commented 6 months ago

Hello! I would like to do some teaching with RStudio.

I don't want - for sure -

  1. to use online "web editors", web R and so on (missing packages I need, slow loading)
  2. to use containers, like docker or virtual machine. Zero-installation on my student's computers.
  3. to rely on my students' local R versions, the set of installed packages, dependencies and so on.
  4. to interfere with my students' computers. Zero changes to their filesystem, registry, appdata, etc. Temporary setting the environment variables (per session) is OK.

What I want is to provide them with a stand-alone, totally independent instance of RStudio with "portable R" located in a subdirectory, with own local library. This would be almost entirely "isolated", "sandboxed" from their environments. After the course they could easily delete the whole directory.

I almost managed to set up such environment by downloading RStudio ZIP and taking portable R (from R Portable - Browse /R-Portable at SourceForge.net ). I can start RStudio from a .BAT file by setting the SET RSTUDIO_WHICH_R=.\R\ ....... environment variable. And it works.

@echo off
SET RSTUDIO_WHICH_R=.\R\R-3.6.2\bin\x64\Rterm.exe
rstudio

But RStudio always restores the last project. Then it loads their last session, packages - and since these packages don't agree with the R version I use (for a purpose), it "spits" dozens of error messages before it starts. And then they have to close the project anyway.

This is definitely not a "zero-interference" approach.

For the R engine I can request "vanilla" model, for instance. Is there any command line switch or any environment variable allowing me to start a completely independent RStudio, ignoring all registry entries, and so on?

Yes, I do know I can uncheck appropriate options in the Tools -> Global Options, but this uses Windows registry I guess. I know it, because when I run the unZIPpped "portable" RStudio it "remembers" things. So this must read the registry...

Briefly - how to launch a clean, local instance of RStudio without reading anything from user's appdata directory?

I asked the question on the community forum. I was told to try the XDG_CONFIG_HOME, so I set it to the local "." directory, copied the necessary files from appdata, updated the

"restore_source_documents": false,
"restore_last_project": false

but it didn't work.

ronblum commented 6 months ago

@adrianolszewski Thanks for the question! What operating system and RStudio version and edition that you're using? From what I can tell, you're running RStudio Server or Posit Workbench on Windows.

adrianolszewski commented 6 months ago

Hello @ronblum, Yes, that is correct - I use RStudio on Windows. But I plan also to support the Linux version, as some of my students use Debian and Slackware based distros. It would be really nice to have an OS-independent solution, but I won't complain for "targeted" solution too :) Anything - just to prevent loading anything during the startup and behave like a "vanilla", fresh installation, independent on the current user's environment.

gtritchie commented 6 months ago

Cross reference to the community thread.

gtritchie commented 6 months ago

Not a solution, but if you want to clean up (most) traces of RStudio Desktop for a user, this script shows what to delete.

Windows: https://github.com/rstudio/rstudio/blob/main/scripts/clean-rstudio.bat Mac/Linux: https://github.com/rstudio/rstudio/blob/main/scripts/clean-rstudio

Note that RStudio does not make much use of the registry on Windows, almost everything is stored in files.

adrianolszewski commented 6 months ago

Thank you very much for the tip (I will use it in other scenario, so useful anyway), but in the given scenario - my students would eat me alive if I cleaned their environments... (or if my teaching required them to clean their preferences). That's why I asked for any non-invasive solutions. Ideally, if RStudio searched for the config files this way:

1) locally; if a user creates the settings file locally, it has the highest priority, ignoring the appdata directory 2) appdata - as currently

gtritchie commented 6 months ago

You can redirect at least some of the saved information to alternate locations, e.g.:

@echo off
SET RSTUDIO_WHICH_R=.\R\R-3.6.2\bin\x64\Rterm.exe
SET RSTUDIO_CONFIG_HOME=%USERPROFILE%\rstudio-settings\config
SET RSTUDIO_DATA_HOME=%USERPROFILE%\rstudio-settings\data
rstudio

This might get you closer to what you want, but in my quick testing, I still see a lot of information being stored in %appdata%\RStudio (which may be a bug, but I need to research that).

adrianolszewski commented 6 months ago

Thank you very much @gtritchie!

It was very helpful! I am almost there with the following content of files:

1) start.bat (please don't mind the super-old version of R. It's only to make sure nothing I use currently is loaded :) )

@echo off
SET RSTUDIO_WHICH_R=.\R\R-3.6.2\bin\x64\R.exe
SET RSTUDIO_CONFIG_HOME=.\
SET RSTUDIO_DATA_HOME=.\
rstudio

2) rstudio-prefs.json

{
    "windows_terminal_shell": "win-cmd",
    "font_size_points": 9,
    "jobs_tab_visibility": "shown",
    "highlight_r_function_calls": true,
    "show_rmd_render_command": true,
    "graphics_backend": "ragg",
    "graphics_antialiasing": "subpixel",
    "use_tinytex": true,
    "auto_append_newline": true,
    "source_with_echo": true,
    "pdf_previewer": "none",
    "full_project_path_in_window_title": true,
    "show_last_dot_value": true,
    "rainbow_parentheses": true,
    "check_arguments_to_r_function_calls": true,
    "warn_variable_defined_but_not_used": true,
    "syntax_color_console": true,
    "show_doc_outline_rmd": true,
    "rmd_auto_date": true,
    "soft_wrap_rmd_files": false,
    "show_terminal_tab": false,
    "handle_errors_in_user_code_only": false,

    "restore_source_documents": false,
    "restore_last_project": false,
    "always_save_history": false,
    "default_open_project_location": "./course",
    "default_project_location": "./course"
}

I separated the modified entries with a blank line.

With these settings, no existing project is loaded and RStudio starts with a clean session. Also the "./course" directory is now "honoured":

That's great!

I would only love if RStudio - when I click the "open file" icon - started in the "./course" directory rather than in the standard "Documents" one: obraz

indeed:

>  getwd()
[1] "................/Documents"

I searched this list: https://docs.posit.co/ide/server-pro/reference/session_user_settings.html but couldn't find an appropriate entry (I'm sorry if I missed it).

PS: in the cmd window I can see some errors, which, however, don't break RStudio and I can work. The "Odmowa dostepu." message says "Access denied"

[19016:0402/021136.526:ERROR:cache_util_win.cc(20)] Unable to move the cache: Odmowa dostepu. (0x5)
[19016:0402/021136.526:ERROR:cache_util_win.cc(20)] Unable to move the cache: Odmowa dostepu. (0x5)
[19016:0402/021136.560:ERROR:disk_cache.cc(205)] Unable to create cache
[19016:0402/021136.560:ERROR:gpu_disk_cache.cc(676)] Gpu Cache Creation failed: -2
[19016:0402/021136.561:ERROR:disk_cache.cc(205)] Unable to create cache
[19016:0402/021136.561:ERROR:gpu_disk_cache.cc(676)] Gpu Cache Creation failed: -2
[29936:0402/021136.580:ERROR:cache_util_win.cc(20)] Unable to move the cache: Odmowa dostepu. (0x5)
[29936:0402/021136.580:ERROR:disk_cache.cc(205)] Unable to create cache
desktop_get_open_file_name
desktop_get_open_file_name
gtritchie commented 6 months ago

Those errors are emitted by Electron and Chromium and can usually be ignored.

gtritchie commented 6 months ago

Try using "initial_working_directory" which corresponds to this setting in the UI:

working-dir

adrianolszewski commented 6 months ago

Thank you, @gtritchie, your help is great and very much appreciated!

This addressed all items on the "todo" list:

It's awesome! By the way, would you consider making a short "tutorial", kinda "technical note" about that? I think more people, especially educators, would be interested in such possibility. And when I close this issue, it will get "buried" deeply and nobody will notice it.

b395f0ab-e690-45a0-bef4-7e19988738da_text

github-actions[bot] commented 3 days ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs, per https://github.com/rstudio/rstudio/wiki/Issue-Grooming. Thank you for your contributions.