You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
R: Find a more robust approach to wait for installation during "Install R Package and Restart R" command #1279
In #1099 we made the "Install R Package and Restart R" command do the following:
install the package via devtools::install()
restart R
run library() for the package
The second two steps are pretty much where we want them to be for the long term, but as of that PR, the way we wait for installation to finish is not great; it checks for a timestamp changing on the package DESCRIPTION file in the library within the runtimePath (from the runtime metadata). R users can in fact change their .libPaths() and keep their packages wherever they want, although that is not a common step to take, especially on a Mac. (Seems like this comes up more often for Windows R users.)
Let's look for a way to improve this situation:
If we could call .libPaths() from the R extension, we could look in what are for sure the right place(s).
If we could check the status of an R runtime (busy/idle), we could find out when devtools::install() was no longer running.
If the executeCode API returned something other than "yep, started that code going", we could probably use that.
to become something that happens in more of a "build pane" like in RStudio, which runs in a separate process rather than in the current R session.
So then we'd be waiting for that process to exit, which I imagine there is some typescript helper for, and that would be our signal of "installation is either finished or errored"
If we could check the status of an R runtime (busy/idle), we could find out when devtools::install() was no longer running.
We are definitely in a better place now (robust to differences in .libPaths()) but there are some remaining problems due to relying to the status (busy vs. idle) of the runtime:
If the installation fails, the runtime is then idle and we go ahead with the restart and try to load the package via library(). We don't want this. 🚫
If the user if prompted for info during devtools::install() (like the upgrade menu) then the runtime is idle while waiting and it tries to restart, which is a pretty bad experience and hard to get out of. 🚫
I do think we'll need to change what executeCode() returns to improve this experience further.
With the changes in #1445 we could try running just the install part as a task in a separate R session and then use problem matchers to know whether to keep going with the restart. So it would be a command made up of:
I have used Positron and the new "R: Install R Package" task to install vroom. Here's the gesture I used (which I now know was wrong; see below):
At first, I encountered an error while installing dependencies:
> devtools::install()
cli (641fe8cb1... -> d8883112a...) [GitHub]
vctrs (0.6.3 -> 0.6.4 ) [CRAN]
fansi (1.0.4 -> 1.0.5 ) [CRAN]
crayon (251368779... -> b3c69cf60...) [GitHub]
Installing 2 packages: vctrs, fansi
Installing packages into ‘/Users/jenny/Library/R/arm64/4.3/library’
(as ‘lib’ is unspecified)
trying URL 'https://p3m.dev/cran/latest/bin/macosx/big-sur-arm64/contrib/4.3/vctrs_0.6.4.tgz'
Content type 'binary/octet-stream' length 1298585 bytes (1.2 MB)
==================================================
downloaded 1.2 MB
trying URL 'https://p3m.dev/cran/latest/bin/macosx/big-sur-arm64/contrib/4.3/fansi_1.0.5.tgz'
Content type 'binary/octet-stream' length 302601 bytes (295 KB)
==================================================
downloaded 295 KB
The downloaded binary packages are in
/tmp/RtmpekNT85/downloaded_packages
Adding ‘fansi_1.0.5.tgz’ to the cache
Adding ‘vctrs_0.6.4.tgz’ to the cache
Error in "INSTALL_opts" %in% names(args) && grepl("--no-test-load", args$INSTALL_opts, :
'length = 2' in coercion to 'logical(1)'
Calls: <Anonymous> ... update_cache -> update_cache_safe -> update_cache_binaries
Execution halted
* The terminal process "/bin/zsh '-l', '-c', '/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/R -e "devtools::install()"'" terminated with exit code: 1.
* Terminal will be reused by tasks, press any key to close it.
Now, that doesn't look like the responsibility of this task (looks like r-lib/crancache#35, which is allegedly closed). I went over to R and did pak::local_install_deps() to try to get the necessary dependencies installed in advance. Interestingly, that did not install exactly the same set of packages 🤔
> pak::local_install_deps()
✔ Updated metadata database: 6.63 MB in 10 files.
✔ Updating metadata database ... done
→ Will update 2 packages.
→ Will download 1 CRAN package (155.72 kB), cached: 2 (162.44 kB).
+ crayon 1.5.1.9000 → 1.5.2
+ glue 1.6.2 → 1.6.2 🔧 ⬇ (155.72 kB)
! crayon and glue are loaded in the current R session, you probably need to
restart R after the installation.
? Do you want to continue (Y/n)
ℹ Getting 1 pkg (155.72 kB), 1 (162.44 kB) cached
✔ Cached copy of glue 1.6.2 (aarch64-apple-darwin20) is the latest build
✔ Got crayon 1.5.2 (aarch64-apple-darwin20) (161.94 kB)
✔ Downloaded 1 package (161.94 kB)in 1.1s
✔ Installed crayon 1.5.2 (23ms)
✔ Installed glue 1.6.2 (41ms)
✔ 22 deps: kept 20, upd 2, dld 1 (161.94 kB) [27.1s]
Then I re-attempted to install vroom with the new task. That lead to installing cli from source (successfully). After that, a successful vroom install.
But in the R console, I didn't see a restart or library(vroom), which surprised me.
Then I went to the command palette and pulled up "R: Install R Package and Restart R". I did that and that seems to have done what's on the tin!
Do we have any thoughts about me mistakenly using the "R: Install R Package" task, when what I actually want is "R: Install R Package and Restart R" from the command palette (Cmd + Shift + B)? Of course, I usually just do Cmd + Shift + B! This only happened because I've recently been accessing tasks that way over in amalthea. Also, I think users will get some exposure to this task, because they'll see it in the terminal. But I'm totally OK if we chalk this up to "user error".
@juliasilge has there already been an analysis/exploration of which arguments to provide to devtools::install() (and therefore to R CMD build and R CMD INSTALL). This is about the behaviour around updating dependencies, i.e. maybe we should be setting the upgrade argument.
I went to compare Positron to RStudio and I see that RStudio is using R CMD INSTALL directly, which surprises me. I have RStudio configured to use devtools, when available, at both the project and user level. Does RStudio not use devtools for "Install"? 🤔 Did it ever do so?
In any case, I would be comfortable closing this and waiting for heavier usage to reveal possible next steps.
I was hoping the names of the task and command would hopefully indicate what they do:
The task is "R: Install R Package" and only installs the package.
The command is "R: Install R Package and Restart R" and does the install/restart/library() dance; this wording matches what folks from RStudio see:
Do we think there could be better naming to help distinguish what these two gestures do? Or should we stick with this for now? I think the name is the only way we have to distinguish them.
When we're ready to add in arguments to devtools::install(), we can set those up as yet more configuration (it's config in RStudio so I think this is fine) and then change the way this string is created to include the args:
We don't think there's any specific call-to-action re: my task vs. command confusion.
We do think that the default behaviour of devtools::install(upgrade = "always") is a problem. For package devs, this frequently leads to attempts to upgrade and install direct/indirect dependencies, from source, from GitHub. It feels like devtools::install() can end up doing too much and more than it was really asked to to, in this use case. Even if you don't mind the upgrades, it exposes the whole task to more reasons to fail, which are arguably unrelated to the job it was asked to do.
We could instead execute devtools::install(upgrade = "never") or devtools::install(upgrade = FALSE). Or we also like the idea of shifting to pak::local_install(upgrade = FALSE), because here upgrade = FALSE aligns much better with what we want:
When FALSE, the default, pak does the minimum amount of work to give you the latest version(s) of pkg. It will only upgrade dependent packages if pkg, or one of their dependencies explicitly require a higher version than what you currently have. It will also prefer a binary package over to source package, even it the binary package is older.
Activity
juliasilge commentedon Sep 11, 2023
Just to be more explicit here, as @jgutman says in #1091:
juliasilge commentedon Sep 11, 2023
Users who install R via rig also have packages installed not in the runtime path.
DavisVaughan commentedon Sep 11, 2023
I think the long term solution is for
to become something that happens in more of a "build pane" like in RStudio, which runs in a separate process rather than in the current R session.
So then we'd be waiting for that process to exit, which I imagine there is some typescript helper for, and that would be our signal of "installation is either finished or errored"
juliasilge commentedon Sep 13, 2023
In #1292, we switched to this option:
We are definitely in a better place now (robust to differences in
.libPaths()) but there are some remaining problems due to relying to the status (busy vs. idle) of the runtime:library(). We don't want this. 🚫devtools::install()(like the upgrade menu) then the runtime is idle while waiting and it tries to restart, which is a pretty bad experience and hard to get out of. 🚫I do think we'll need to change what
executeCode()returns to improve this experience further.jgutman commentedon Sep 13, 2023
juliasilge commentedon Sep 13, 2023
jgutman commentedon Sep 13, 2023
juliasilge commentedon Oct 3, 2023
With the changes in #1445 we could try running just the install part as a task in a separate R session and then use problem matchers to know whether to keep going with the restart. So it would be a command made up of:
positron.runtime.restartLanguageRuntime()executeCode()to dolibrary()jennybc commentedon Oct 17, 2023
I have used Positron and the new "R: Install R Package" task to install vroom. Here's the gesture I used (which I now know was wrong; see below):
At first, I encountered an error while installing dependencies:
Now, that doesn't look like the responsibility of this task (looks like r-lib/crancache#35, which is allegedly closed). I went over to R and did
pak::local_install_deps()to try to get the necessary dependencies installed in advance. Interestingly, that did not install exactly the same set of packages 🤔Then I re-attempted to install vroom with the new task. That lead to installing cli from source (successfully). After that, a successful vroom install.
But in the R console, I didn't see a restart or
library(vroom), which surprised me.Then I went to the command palette and pulled up "R: Install R Package and Restart R". I did that and that seems to have done what's on the tin!
Do we have any thoughts about me mistakenly using the "R: Install R Package" task, when what I actually want is "R: Install R Package and Restart R" from the command palette (Cmd + Shift + B)? Of course, I usually just do Cmd + Shift + B! This only happened because I've recently been accessing tasks that way over in amalthea. Also, I think users will get some exposure to this task, because they'll see it in the terminal. But I'm totally OK if we chalk this up to "user error".
@juliasilge has there already been an analysis/exploration of which arguments to provide to
devtools::install()(and therefore toR CMD buildandR CMD INSTALL). This is about the behaviour around updating dependencies, i.e. maybe we should be setting theupgradeargument.I went to compare Positron to RStudio and I see that RStudio is using
R CMD INSTALLdirectly, which surprises me. I have RStudio configured to use devtools, when available, at both the project and user level. Does RStudio not use devtools for "Install"? 🤔 Did it ever do so?In any case, I would be comfortable closing this and waiting for heavier usage to reveal possible next steps.
juliasilge commentedon Oct 18, 2023
I was hoping the names of the task and command would hopefully indicate what they do:
library()dance; this wording matches what folks from RStudio see:Do we think there could be better naming to help distinguish what these two gestures do? Or should we stick with this for now? I think the name is the only way we have to distinguish them.
When we're ready to add in arguments to
devtools::install(), we can set those up as yet more configuration (it's config in RStudio so I think this is fine) and then change the way this string is created to include the args:positron/extensions/positron-r/src/tasks.ts
Line 40 in 47ae2d2
jennybc commentedon Oct 18, 2023
From discussion elsewhere:
We don't think there's any specific call-to-action re: my task vs. command confusion.
We do think that the default behaviour of
devtools::install(upgrade = "always")is a problem. For package devs, this frequently leads to attempts to upgrade and install direct/indirect dependencies, from source, from GitHub. It feels likedevtools::install()can end up doing too much and more than it was really asked to to, in this use case. Even if you don't mind the upgrades, it exposes the whole task to more reasons to fail, which are arguably unrelated to the job it was asked to do.We could instead execute
devtools::install(upgrade = "never")ordevtools::install(upgrade = FALSE). Or we also like the idea of shifting topak::local_install(upgrade = FALSE), because hereupgrade = FALSEaligns much better with what we want: