Positron Rprofile.site

Is there a way to get positron to recognize Rprofile.site? I use this to manage a group of users in Rstudio but haven’t gotten it to work in positron. Thanks.

Can you say more about how you are using Rprofile.site with Positron? My understanding is that applies to a whole server such as Workbench or RStudio Server and Positron is currently only available as a desktop app.

We are running Rstudio server. I wrote a custom R environment for my lab group similar to renv but with some important differences. As part of this, I use Rprofile.site for many things: set repos, create and set lib paths, write log files to a specific location, check that users are working in projects, etc.
This gets sourced before user/project .Rprofile files whenever R starts via Rstudio, Rstudio server, or the command line. Anyways Positron seems to skip the Rprofile.site.

looks like positron starts R with
ark --interactive --no-restore-data --no-site-file --no-init-file
which is probably why the site file is ignored. Interestingly it does read the Renviron.site file.

Can you say more about how you are running Positron itself, though? Positron does not have a server version.

I am running Positron on Windows and connecting to my Linux server running R4.4.0 via ssh.

Ah, thanks! Just so I am super clear, is your Rprofile.site on the remote server, where R is installed?

Yes Rprofile.site is on the remote server.

@blaserlab we see you said that ark is started with ark --interactive --no-restore-data --no-site-file --no-init-file, and we'd like to look into that a little more.

In the Output channel named something like R x.y.z: Console, close to the very top do you see the command that starts ark? Is that where you got this information from? Can you please share that section of the logs?

Also, is it possible you are setting the "Extra Arguments" setting and passing --no-site-file through? (Make sure that you are looking at the SSH server settings when checking)

I have not changed how the R process itself boots, i.e. the only modifications I have made are to .Rprofile and .Renviron at different levels (user, project, system)

I used the startup package to debug this issue. I don't see the output channel you describe. But here is the console output when I run startup::startup(debug = TRUE). Note that it looks like R is skipping the user and project level .Rprofile as well here (I have the startup command in both places and it isn't running until I enter the command in the console.) This is consistent with the debug info.

R 4.4.0 restarted.

startup::startup(debug = TRUE)

0.000s: System information:

0.002s: - R_HOME: '/usr/local/lib/R' (existing folder)

0.003s: - R call: ark --interactive --no-restore-data --no-site-file --no-init-file

0.004s: - Current directory: '/workspace/brad_workspace/test_proj'

0.009s: - User's home directory: '~' => '/home/OSUMC.EDU/blas02' (existing folder)

0.012s: - User's 'startup' config directory: '/home/OSUMC.EDU/blas02/.config/R/startup' (non-existing directory)

0.013s: - Search path: '.GlobalEnv', '.env', 'tools:rstudio', 'tools:positron', 'package:stats', 'package:graphics', 'package:grDevices', 'package:utils', 'package:datasets', 'package:methods', 'Autoloads', 'package:base'

0.014s: - Loaded namespaces: 'compiler', 'startup', 'magrittr', 'cli', 'graphics', 'tools', 'pillar', 'fs', 'glue', 'utils', 'tibble', 'grDevices', 'stats', 'utf8', 'fansi', 'datasets', 'vctrs', 'data.table', 'methods', 'lifecycle', 'pkgconfig', 'rlang', 'base'

0.015s: The following has already been processed by R:

0.022s: - '/usr/local/lib/R/etc/Renviron' (22 lines; 1836 bytes) setting 22 environment variables ('R_PLATFORM', 'R_PAPERSIZE_USER', 'R_PAPERSIZE', 'R_PRINTCMD', 'R_RD4PDF', 'R_TEXI2DVICMD', 'R_GZIPCMD', 'R_UNZIPCMD', 'R_ZIPCMD', 'R_BZIPCMD', 'R_BROWSER', 'EDITOR', 'PAGER', 'R_PDFVIEWER', 'LN_S', 'MAKE', 'SED', 'TAR', 'R_STRIP_SHARED_LIB', 'R_STRIP_STATIC_LIB', 'R_LIBS_USER', 'R_LIBS_SITE')

0.023s: - R_ENVIRON: ''

0.028s: - Renviron file: '/usr/local/lib/R/etc/Renviron.site' (4 lines; 227 bytes) setting 4 environment variables ('R_PKG_CACHE_DIR', 'BLASERTEMPLATES_CACHE_ROOT', 'GITHUB_PAT', 'RETICULATE_PYTHON')

0.029s: - R_ENVIRON_USER: ''

0.033s: - User Renviron file: '~/.Renviron' => '/home/OSUMC.EDU/blas02/.Renviron' (4 lines; 218 bytes) setting 4 environment variables ('GITHUB_PAT', 'R_PKG_CACHE_DIR', 'BLASERTEMPLATES_CACHE_ROOT', 'BLASERTEMPLATES_PROJECTS')

0.035s: - tempdir(): '/tmp/RtmpynweXt' (existing folder)

0.036s: - TMPDIR: ''

0.036s: - TMP: ''

0.037s: - TEMP: ''

0.037s: - R_LIBS: ''

0.037s: - R_LIBS_SITE: '/usr/local/lib/R/site-library'

0.038s: - R_LIBS_USER: '/home/OSUMC.EDU/blas02/R/x86_64-pc-linux-gnu-library/4.4'

0.038s: - R_SCRIPT_DEFAULT_PACKAGES (only if Rscript was used): ''

0.039s: - R_DEFAULT_PACKAGES: '' (= 'base,methods,datasets,utils,grDevices,graphics,stats')

0.042s: - '/usr/local/lib/R/library/base/R/Rprofile' (140 code lines; 7077 bytes)

0.043s: - R_PROFILE: ''

0.046s: - '/usr/local/lib/R/etc/Rprofile.site' (171 code lines; 6434 bytes)

0.046s: - Skipped site Rprofile startup file, because R was launched with command-line option --no-site-file

0.047s: - Positron option '--no-init-file' has no effect, despite being specified

0.047s: - R_PROFILE_USER: ''

0.051s: - '.Rprofile' (1 code lines; 31 bytes)

0.051s: startup::startup()-specific processing ...

0.053s: Found 'startup' directory '~/.Renviron.d'.

0.060s: Found 'startup' directory '~/.Rprofile.d'.

0.065s: - Positron option '--no-init-file' has no effect, despite being specified

0.066s: Processing 1 Rprofile files ...

0.068s: - '/home/OSUMC.EDU/blas02/.Rprofile.d/options.R' (16 code lines; 426 bytes)

0.072s: Processing 1 Rprofile files ... done

0.082s: - unloading the 'startup' package

0.082s: - Search path: '.GlobalEnv', '.env', 'tools:rstudio', 'tools:positron', 'package:stats', 'package:graphics', 'package:grDevices', 'package:utils', 'package:datasets', 'package:methods', 'Autoloads', 'package:base'

0.083s: - Loaded namespaces: 'compiler', 'magrittr', 'cli', 'graphics', 'tools', 'pillar', 'fs', 'glue', 'utils', 'tibble', 'grDevices', 'stats', 'utf8', 'fansi', 'datasets', 'vctrs', 'data.table', 'methods', 'lifecycle', 'pkgconfig', 'rlang', 'base'

0.083s: startup::startup()-specific processing ... done

0.083s: The following will be processed next by R:

0.083s: - Skipping any RData file, because R was launched with command-line option --no-restore-data

0.084s: - R_HISTFILE: ''

0.084s: - .First(): in '.GlobalEnv' (position 1 on search())

0.084s: - Remaining packages per R_DEFAULT_PACKAGES to be attached by base::.First.sys() (in order):

0.085s: - The R just-in-time (JIT) compiler:

0.085s: - R_ENABLE_JIT:

0.085s: - JIT compiler enabled by default

0.086s: The following will be processed when R terminates:

0.086s: - .Last(): in '.GlobalEnv' (position 1 on search()); circumvented by quit(runLast = FALSE)

0.086s: - .Last.sys(): no such function on search()

This is the output channel I am asking for

If you use the Show output channels... command then you should be able to pull it up

If you could provide everything you see in that output channel then that would be helpful.

Oh you use startup::startup()? In that case I have a guess as to what is happening. Can you also post the full logs of the output channel R x.y.z: Kernel (it should be right next to the one for Console). That will help me confirm.

2025-01-14 14:22:30.879 [info] R 4.4.0 session 'r-732ba041' created in /home/OSUMC.EDU/blas02/brad_workspace/test_proj with command:

2025-01-14 14:22:30.879 [info] /home/OSUMC.EDU/blas02/.positron-server/bin/c5ce275dc502f6b15433b271802cb33e1ba5ef68/extensions/positron-r/resources/ark/ark --connection_file {connection_file} --log /tmp/kernel-voXkSh/kernel.log --startup-file /home/OSUMC.EDU/blas02/.positron-server/bin/c5ce275dc502f6b15433b271802cb33e1ba5ef68/extensions/positron-r/resources/scripts/startup.R --session-mode console -- --interactive --no-restore-data

2025-01-14 14:22:30.879 [debug] State: uninitialized => starting (invoking start API)

2025-01-14 14:22:32.301 [debug] Connecting to websocket: ws://localhost:57603/sessions/r-732ba041/channels

2025-01-14 14:22:32.306 [debug] Connected to websocket ws://localhost:57603/sessions/r-732ba041/channels.

2025-01-14 14:22:32.306 [info] Kernel is ready.

2025-01-14 14:22:32.306 [debug] State: starting => ready (new session)

2025-01-14 14:22:32.307 [info] Kernel is ready.

2025-01-14 14:22:32.307 [debug] State: ready => ready (initial heartbeat received)

2025-01-14 14:22:32.307 [debug] State: ready => busy (kernel_info_request)

2025-01-14 14:22:32.307 [debug] State: busy => idle (kernel_info_request)

2025-01-14 14:22:32.308 [info] Starting Positron LSP server on port 53703

2025-01-14 14:22:32.308 [info] Starting LSP server positron-lsp-r-487f0194 for 127.0.0.1:53703

2025-01-14 14:22:32.309 [debug] Starting DAP server positron-dap-r-4240b9ba for 127.0.0.1:65332

2025-01-14 14:22:32.309 [debug] State: idle => busy (comm_info_request)

2025-01-14 14:22:32.309 [debug] State: busy => idle (comm_info_request)

2025-01-14 14:22:32.310 [debug] State: idle => busy (comm_open)

2025-01-14 14:22:32.352 [debug] State: busy => idle (comm_open)

2025-01-14 14:22:32.352 [debug] State: idle => busy (comm_open)

2025-01-14 14:22:32.352 [debug] State: busy => idle (comm_open)

2025-01-14 14:22:32.352 [info] Unknown DAP command: server_started

2025-01-14 14:22:32.362 [debug] State: idle => busy (comm_open)

2025-01-14 14:22:32.408 [info] Set initial console width to 198

2025-01-14 14:22:32.412 [debug] State: busy => idle (comm_open)

2025-01-14 14:22:32.454 [debug] State: idle => busy (comm_open)

2025-01-14 14:22:32.454 [debug] State: busy => idle (comm_open)

2025-01-14 14:22:32.454 [debug] State: idle => busy (comm_info_request)

2025-01-14 14:22:32.454 [debug] State: busy => idle (comm_info_request)

2025-01-14 14:22:32.454 [debug] State: idle => busy (comm_open)

2025-01-14 14:22:32.538 [debug] State: busy => idle (comm_open)

2025-01-14 14:22:32.538 [debug] State: idle => busy (comm_info_request)

2025-01-14 14:22:32.539 [debug] State: busy => idle (comm_info_request)

2025-01-14 14:22:32.541 [debug] State: idle => busy (comm_info_request)

2025-01-14 14:22:32.541 [debug] State: busy => idle (comm_info_request)

2025-01-14 14:22:32.541 [debug] State: idle => busy (comm_msg)

2025-01-14 14:22:32.541 [debug] State: busy => idle (comm_msg)

2025-01-14 14:22:32.542 [debug] State: idle => busy (comm_open)

2025-01-14 14:22:32.548 [debug] State: busy => idle (comm_open)

Sorry the previous was the console log. The following is the kernel log

** Begin kernel log for session R 4.4.0 (r-732ba041) at 1/14/2025, 2:22:30 PM **
Streaming kernel log file: /tmp/kernel-voXkSh/kernel.log
[R] 2025-01-14T19:22:32.412094Z ERROR Can't populate srcref for startup: Can't find binding startup in environment
[R]
[R] Stack backtrace:
[R] 0:
[R] 1:
[R] 2:
[R] 3:
[R] 4:
[R] 5: R_withCallingErrorHandler
[R] 6:
[R] 7: R_ToplevelExec
[R] 8:
[R] 9:
[R] 10:
[R] 11:
[R] 12:
[R] 13: R_withCallingErrorHandler
[R] 14:
[R] 15: R_ToplevelExec
[R] 16:
[R] 17:
[R] 18: Rf_ReplIteration
[R] 19:
[R] 20: run_Rmainloop
[R] 21:
[R] 22:
[R] 23:
[R] 24:
[R] 25:
[R] 26:
[R] 27:
[R] 28: __libc_start_call_main
[R] at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
[R] 29: __libc_start_main_impl
[R] at ./csu/../csu/libc-start.c:392:3
[R] 30:
[R] at crates/ark/src/interface.rs:2011
[R]
[R] 2025-01-14T19:23:52.419540Z ERROR Can't populate srcref for startup: Can't find binding startup in environment
[R]
[R] Stack backtrace:
[R] 0:
[R] 1:
[R] 2:
[R] 3:
[R] 4:
[R] 5: R_withCallingErrorHandler
[R] 6:
[R] 7: R_ToplevelExec
[R] 8:
[R] 9:
[R] 10:
[R] 11:
[R] 12:
[R] 13: R_withCallingErrorHandler
[R] 14:
[R] 15: R_ToplevelExec
[R] 16:
[R] 17:
[R] 18: Rf_ReplIteration
[R] 19:
[R] 20: run_Rmainloop
[R] 21:
[R] 22:
[R] 23:
[R] 24:
[R] 25:
[R] 26:
[R] 27:
[R] 28: __libc_start_call_main
[R] at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
[R] 29: __libc_start_main_impl
[R] at ./csu/../csu/libc-start.c:392:3
[R] 30:
[R] at crates/ark/src/interface.rs:2011
[R]

@blaserlab to be very clear, are you using Rprofile.site to run startup::startup(), and then you rely on startup to run other Rprofile.d files?

My guess is that your Rprofile.site is running, but the call to startup::startup() isn't doing what you expect. startup::startup() looks at the value of commandArgs() and makes decisions based on whether or not --no-site-file is present. We explicitly set that to prevent R itself from running your site profile (which happens too early for us to correctly handle) and then we run your site profile "manually" ourselves. I imagine startup::startup() is getting confused by this.

If you remove the startup::startup() call from your Rprofile.site and replace it with x <- 10, then when you start up R can you type x in the console and get 10 back?

I've opened Set `R_set_command_line_arguments()` to reflect what actually happens · Issue #670 · posit-dev/ark · GitHub to track this, as I think I have an idea of what is going on.

Sorry but I think I gave you a red herring with the startup::startup() bit. I really only turned to that option to debug the startup procedure.

Your suggestion to try x <- 10 was very helpful. I was previously debugging this using cat("Hello from site/home/project"). None of these display in the console. However when I assign a variable like you suggest, it shows that all Rprofile scripts are at least attempted to be sourced. Rprofile.site then either ~/.Rprofile or project-level .Rprofile, the latter overriding the former.

It looks like most of the code in Rprofile.site is being run invisibly. There are several startup messages that are not displayed but it looks like the repos and .libPaths are being set correctly. .First and .Last are defined but not run on session start and exit. This messes up my log files. There are a few other custom things that I would have to test. But it looks like 80-90% of the functionality is there. Maybe these are consequences of running the site profile manually?

Anyways, it's pretty interesting to see how R in positron is different from Rstudio in terms of startup. Command line R seems to be very similar to Rstudio in this way.

We have a very custom setup using Rstudio which is good for beginning and intermediate users and I think most of them should stay with that. Some of the more advanced computational people in my group may find positron a good alternative, however, since we are doing more with python these days. Thanks for your help on this...I'll keep an eye out for developments as the project moves forward.