Skip to content

R: update behavior for 'r.packageBuild' command #1091

Closed

Description

@juliasilge

Originally I put devtools::build() in this 'r.packageBuild' command in the R extension:

https://github.com/rstudio/positron/blob/9b4618b58b35b73466e415ecb8fb3d96e83ad737/extensions/positron-r/src/commands.ts#L56

However, a better choice would be:

  • devtools::install()
  • restart R
  • library(package_name)

Activity

  1. self-assigned this
    on Aug 17, 2023
  2. added this to the Private Alpha milestone on Sep 8, 2023
  3. jgutman commented on Sep 11, 2023

    @jgutman
    Contributor

    I might be doing something wrong here, but I'm trying this out in Positron 2023.09.0+83 with the workspace open to the reticulate package, and R 4.3.1 arm64. I do Cmd+Shift+B, and it starts devtools::install() as expected, but then I get an error and it doesn't proceed to restart + library [EDIT: actually apparently it DOES proceed to library + restart, but only after a long delay of at least several minutes during which it looks like it isn't doing anything, and the library call fails anyway since it didn't actually install successfully]

    ** byte-compile and prepare package for lazy loading
    Error in eval(exprs[i], envir) : object 'x' not found
    Error: unable to load R code in package ‘reticulate’
    Execution halted
    ERROR: lazy loading failed for package ‘reticulate’
    * removing ‘/Users/jacquelinegutman/Library/R/arm64/4.3/library/reticulate’
    
    image
    > R.home()
    [1] "/Library/Frameworks/R.framework/Resources"
    > .libPaths()
    [1] "/Users/jacquelinegutman/Library/R/arm64/4.3/library"                 
    [2] "/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library"
    
  4. juliasilge commented on Sep 11, 2023

    @juliasilge
    MemberAuthor

    That is the currently expected behavior if devtools::install() fails, yes. The timeout may be too long:

    const timeout = Date.now() + 3e5;

    I haven't done a lot of work developing reticulate but it doesn't shock me that devtools::install() fails for it.

  5. jgutman commented on Sep 11, 2023

    @jgutman
    Contributor

    Yeah, I tried with rsconnect, where the install succeeds, but it's also a confusingly long delay before restarting

    image

    I'm not sure if it's waiting for something? I have a console prompt, and I can code and do whatever, but there's no restart (at least not for a long while)

  6. DavisVaughan commented on Sep 11, 2023

    @DavisVaughan
    Contributor

    I also do not see a restart or a library() call

    Screenshot 2023-09-11 at 1 46 26 PM
  7. juliasilge commented on Sep 11, 2023

    @juliasilge
    MemberAuthor

    @DavisVaughan what is your .libPaths()?

    For context here, when we do devtools::install(), there is no way to directly tell when it has finished. What I did in #1099 has a not-so-great heuristic looking for the package to be updated in the runtime path library, but R users can set their .libPaths() to be whatever they want and I am guessing that is what is happening here.

  8. juliasilge commented on Sep 11, 2023

    @juliasilge
    MemberAuthor

    When we register a runtime, is it possible to store .libPaths() in the runtime metadata?

  9. jgutman commented on Sep 11, 2023

    @jgutman
    Contributor

    That is the currently expected behavior if devtools::install() fails, yes. The timeout may be too long:

    const timeout = Date.now() + 3e5;

    I haven't done a lot of work developing reticulate but it doesn't shock me that devtools::install() fails for it.

    Ideally, if devtools::install fails, we should probably cancel the restart and library call as they don't really make sense if the install failed -- I think it's okay to file that as an issue for future improvement and leave the expected behavior here same for failure or success.

    I actually have no idea how I ended up with a libPaths that doesn't point to the same directory as my actual R installation, but 🤷‍♀️

  10. DavisVaughan commented on Sep 11, 2023

    @DavisVaughan
    Contributor
    > .libPaths()
    [1] "/Users/davis/Library/R/arm64/4.3/library"                            
    [2] "/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library"

    This is the Rig approved™️ user library that it sets up for you.

    Rig is very adamant that you should not be using your R system package library ([2] from above) as the same location as your general R package library ([1] from above for me).

    AFAICT, Mac and maybe Linux are the only platforms where it is even possible to have 1 folder that holds both CRAN packages and R system packages like base. On Windows I think you get a user library in a different location by default.


    So I think this comment was correct about needing something more robust for finding the DESCRIPTION file
    https://github.com/posit-dev/positron/pull/1099/files#r1319086271

  11. jgutman commented on Sep 11, 2023

    @jgutman
    Contributor

    Ah, yeah I did use Rig and in that case every user using rig or using Windows is going to run into this behavior, so that seems like a very common scenario especially for package developers (but at least we don't need to worry about the Windows situation quite yet)

  12. DavisVaughan commented on Sep 11, 2023

    @DavisVaughan
    Contributor

    Another just-to-get-by option for Alpha is to bind the shortcut to a custom function like .ps.install() which does something like

    .ps.install <- function() {
        devtools::install()
        writeLines("done", some_file_path_we_know_about_on_the_positron_side)
    }

    So .ps.install() would show up in the Console, at least for now, but that is ok if we eventually want a build pane.

    And then on the Positron side you'd be waiting for "done" to appear in some specific file you know about, rather than trying to track down a DESCRIPTION file (likely with some timeout in case the user cancels the operation or the install fails)

  13. jgutman commented on Sep 11, 2023

    @jgutman
    Contributor

    For Davis's suggestion above, I think we'd want to modify that a bit for something that could differentiate between devtools::install failed versus devtools::install is still working

  14. juliasilge commented on Sep 12, 2023

    @juliasilge
    MemberAuthor

    @jgutman and @DavisVaughan would either/both of you be willing to install from main and try again? The new approach here does not assume wrong things about .libPaths() and instead works directly with the runtime in the R extension.

  15. DavisVaughan commented on Sep 13, 2023

    @DavisVaughan
    Contributor

    @juliasilge and I have determined that this is currently working, but if you are requested by install() to update packages then it will no longer work (as mentioned in #1279 (comment)). That does happen somewhat often, but we can document in the private alpha docs how to work around this for now (manually install those packages before hitting the keybinding), and #1279 can be the tracking issue for fixing this now.

    It is likely we will need to implement a different approach to fix #1279, because we are currently looking for an idle state, but that's exactly what the installation menu prematurely sends the runtime into

  16. locked as resolved and limited conversation to collaborators on Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions