Repository navigation
New install + restart behavior for R packages - #1099
Conversation
| }, | ||
| { | ||
| "command": "r.packageBuild", | ||
| "command": "r.packageInstall", |
There was a problem hiding this comment.
I kept the r.packageBuild command as is and instead we now map the r.packageInstall command to the Cmd Shift B keybinding.
|
For lack of a better place to note/discuss this: RStudio actually preserves the global workspace when you do Build > Install, even if you are a person who normally does not save/load the global workspace when restarting R. I've always had mixed feelings about this and can definitely get on board with Positron not preserving the workspace (which is how this PR will behave), as part of its more general posture towards encouraging workspace discipline and hygiene. But we should all note that this is going to be a difference that people probably notice. Hopefully they'll like it! |
|
I'd expect that for some users that are using a test dataset to iterate on a package (e.g. keep plotting the same thing over and over) that this would be quite annoying as they can't just arrow up to re-execute the plot (as they'd need to first load/transform the data). That said, I think those users would be well served by |
| return new Promise(resolve => { setTimeout(resolve, ms); }); | ||
| }; | ||
|
|
||
| if (oldTimestamp === null) { |
There was a problem hiding this comment.
This is the case where the package hasn't been installed yet at all.
| while (!fs.existsSync(libraryPath)) { | ||
| await wait(1000); | ||
| } | ||
| } else { |
There was a problem hiding this comment.
This is the more typical re-installation case.
|
The last piece we needed here was to wait while I tested this out for packages that have already been installed and never been installed, and things seem to be working OK: install-restart.movYou can see that the package is in fact attached after it's done. Some differences from the RStudio behavior include:
I could be convinced both of these are neutral to improvements, but am open of course to what works out best later for these issues. |
|
If |
| case positron.RuntimeClientState.Closing: | ||
| case positron.RuntimeClientState.Closed: { | ||
| out.reject(new Error( `Comm ${this._id} closed before connecting`)); | ||
| out.reject(new Error(`Comm ${this._id} closed before connecting`)); |
There was a problem hiding this comment.
The whitespace change here and in utils.ts happened because I just opened the files. I just spent some time trying to undo these without much success. OK to leave in, since they are our files?
There was a problem hiding this comment.
The linting is AGGRESSIVE! 😆
| const runningRuntimes = await positron.runtime.getRunningRuntimes('r'); | ||
| // For now, there will be only one running R runtime: | ||
| const runtimePath = runningRuntimes[0].runtimePath; | ||
| const originalTimeStamp = getPackageDescriptionTimestamp(runtimePath, packageName); |
There was a problem hiding this comment.
Are we guaranteed that the runtime path is also the root of the library folder? (wondering if we need to check e.g. .libPaths())
There was a problem hiding this comment.
I am hesitant to guarantee anything given the wild world of people's R installations. However, I don't know how we would call .libPaths() from the R extension currently. We could call it via executeCode in the console (but wouldn't be able to capture the output) or via R -e in the terminal (definitely not guaranteed to be the right runtime at all); neither of those is what we want. This is like something @jennybc has mentioned a few times, that she believes we'll eventually need a way to run a tiny bit of R code in a way hidden to the user, in a separate/clean process, but in the right R runtime.
Do you think we should pursue some way of doing this now?
There was a problem hiding this comment.
To step back a moment, the challenge is how to wait while some code finishes, when we don't currently have a great option for that. This option of checking for a file on disk changing is also not great, but what do we want to do about it right now? If this isn't robust enough for our next steps, some options I can think of are:
- create a way for the R extension to query whether a runtime is busy/idle/etc
- change what
executeCodereturns to fill this need - make a way for the extension to call the right R runtime in a way hidden from the user and get return values back into TypeScript
There was a problem hiding this comment.
Well, I'm really more interested in your assessment of how often this simplifying assumption of "runtime path = library path" will hold. If it's the > 90% case then we can merge it as is but file an issue to deal with later.
It's true we need a way to execute R and get results, but we definitely don't want to try to invent that for this PR.
There was a problem hiding this comment.
In my experience with teaching and such, I see non-default (or "personal") libraries much more often for Windows R users. If we are talking about Mac users, I would estimate that very few would have problems with runtimePath also being where to find the library, and >90% seems right. I do think we'll need to change this by the time we have Windows users. I outlined next steps for this in #1279.
jmcphers
left a comment
There was a problem hiding this comment.
This LGTM presuming you don't think the runtime/library path issue is going to be a problem for most folks!
|
Thanks again! I outlined the limitations of this approach and possible next steps in #1279, and that would be a great place for other clever ideas of how to improve this. |

Addresses #1091
This doesn't quite work yet because it does not actually wait for the runtime to restart.