Skip to content

devtools::install() (CMD + SHIFT + B) and keep_sources problem #1733

Description

@DavisVaughan

Right now, CMD + SHIFT + B will install your package without sources. This means that file based hyperlinks, like shown in rlang error tracebacks, won't show up.

Screenshot 2023-10-31 at 11 00 58 AM

Alternatively, we can set keep_sources = TRUE, but this doesn't work either because the installation process happens in a separate temporary folder where the package has been copied to (I think).

Screenshot 2023-10-31 at 11 03 14 AM

This might actually be the reason RStudio still uses R CMD INSTALL for this. It installs in the directory it was called in, so the sources will point to the right location.

Activity

  1. DavisVaughan commented on Oct 31, 2023

    @DavisVaughan
    ContributorAuthor

    devtools::install(keep_source = TRUE, build = FALSE) would work, as it doesn't call pkgbuild::build() first (which is what builds in a new directory). It just installs from what is already there in the package directory

  2. jennybc commented on Oct 31, 2023

    @jennybc
    Member

    I wonder if we can accomplish this (keeping source refs) at the same time as switching to pak (#1631). A quick experiment with pak::pak() and pak::local_install() appears to not install with source refs and there's no obvious argument with which to request that. But we could probably also argue for this feature in pak.

  3. lionel- commented on Feb 16, 2024

    @lionel-
    Contributor

    because the installation process happens in a separate temporary folder where the package has been copied to

    These could be opened in virtual editors. The file can be recreated from the info stored in the srcref attributes.

  4. lionel- commented on Apr 9, 2025

    @lionel-
    Contributor

    I've added this issue to #7176 because the difference between directly installing from a source repository with R CMD install versus installing from a built tarball created with R CMD build is also important for debugging C and C++ code. Installing from a built tarball prevents the debugger from finding the source information.

    By default the shared library built by R doesn't contain any source information for debugging even if it is linked with debug symbols. Instead, it contains references to object files in the build directory that contain the debug info. This mechanism is intended for dev builds because it's very fast. The linker only needs to insert special symbols containing paths to the object files:

    > nm -a /Users/lionel/R/Library/4.4-aarch64/rlang/libs/rlang.so | grep OSO
    0000000067ed4ae1 - 00 0001   OSO /Users/lionel/Sync/Projects/R/r-lib/rlang/src/capture.o
    0000000067ef785b - 00 0001   OSO /Users/lionel/Sync/Projects/R/r-lib/rlang/src/internal.o
    0000000067ef785b - 00 0001   OSO /Users/lionel/Sync/Projects/R/r-lib/rlang/src/rlang.o
    0000000067ed4ae1 - 00 0001   OSO /Users/lionel/Sync/Projects/R/r-lib/rlang/src/version.o
    

    If you call dwarfdump on these object files you'll see the source information in there which looks like this for SEXP for instance:

    0x0000ebdc:   DW_TAG_typedef
                    DW_AT_type      (0x0000ebe5 "SEXPREC *")
                    DW_AT_name      ("SEXP")
                    DW_AT_decl_file ("/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/include/Rinternals.h")
                    DW_AT_decl_line (183)
    

    There is more info about how this works in https://developer.apple.com/forums/thread/775650 if you're curious.

    The nm output above is for a package installed from source. But note what happens when the package is installed from a built tarball:

    > nm -a /Users/lionel/R/Library/4.4-aarch64/rlang/libs/rlang.so | grep OSO
    0000000067ef7d43 - 00 0001   OSO /private/tmp/RtmpIM0xjp/R.INSTALLe9c020cfb3cd/rlang/src/capture.o
    0000000067ef7d43 - 00 0001   OSO /private/tmp/RtmpIM0xjp/R.INSTALLe9c020cfb3cd/rlang/src/internal.o
    0000000067ef7d43 - 00 0001   OSO /private/tmp/RtmpIM0xjp/R.INSTALLe9c020cfb3cd/rlang/src/rlang.o
    0000000067ef7d43 - 00 0001   OSO /private/tmp/RtmpIM0xjp/R.INSTALLe9c020cfb3cd/rlang/src/version.o
    

    These paths now point to a temporary location which prevents the debugger from finding out where symbols are defined in the source repository.

    One alternative is to build the tarball with the --dsym option. This prompts the linker to build a dSYM sidecar file where all the dwarf info from object files are compiled. I considered getting devtools and pak do that by default but this doesn't help much because the dwarf info in the sidecar file points to source files in the temporary package install location. It's possible to remap the source paths with an LLDB command like:

    settings set target.source-map /private/tmp/Rtmpnl5XgE/R.INSTALLe5133dcc3211/rlang /Users/lionel/Sync/Projects/R/r-lib/rlang
    

    But really it's just simpler to install from source, which we have learned should be reliable enough since this has been the default in RStudio for a long time.

  5. lionel- commented on Apr 9, 2025

    @lionel-
    Contributor

    I talked with @gaborcsardi to learn more about the difference between installing from source versus installing from a source tarball. Here is what happens schematically under the hood:

    # Installing from source
    R CMD install /my/source/repo
    
    # Installing from a built tarball
    R CMD build /my/source/repo
    R CMD install mypkg.tgz

    In devtools terms:

    # Installing from source
    devtools::install(build = FALSE)
    
    # Installing from a built tarball
    devtools::install(build = TRUE)

    pak can only install from built tarballs currently because this has been considered the most authentic way of installing a package. It makes sure the process is exactly the same as installing a package from CRAN.

    That said, installing from source is an essential part of the development workflow of non-devtools users who don't have load_all(). It allows incremental rebuilding of native sources via the make system of R packages, and it also is the only way to get source references pointing to the correct source locations, both at R and at C/C++ level (cf my previous comment).

    There were some discussions a while ago about removing the possibility of installing from source because of the two different code paths to maintain and the small discrepancies between the two methods. However the conclusion was that there is no practical alternative to installing from source (besides load_all() for devtools users) so the decision was made to keep it. Also as @DavisVaughan has noted, installing from source is what RStudio has been doing, so it's likely reliable enough for our purposes.

    Gabor agrees we should add source install to pak but that is not implemented yet. Here is what I propose:

    • Make two variants of install commands, one for "installing for development", and another for "installing for production". The development variant installs from source using devtools::install(build = FALSE, keep_source = TRUE), the production variant installs from a built tarball with the pak command we're currently using.

    • Change the default gestures (keybindings or button when we have one) to use the development variant. Installing for production would be done via the command palette.

    Alternatively, to make things simpler, we could have a single variant that always installs for development. The advantage of having two commands is that it is a way of discovering the difference between the two modes of installation. The production command also would compile with optimisations turned on so it would be what you'd use before performing benchmarks on your package.

    If we do include both variants, I think both of them should include R-level source references though. Although they do not point to the right location we can still use them to create virtual document (feature tracked in #2282).

  6. juliasilge commented on Dec 4, 2025

    @juliasilge
    Member

    Related to #2955

  7. removed this from the 2026 Backlog milestone on Jan 27, 2026
  8. 2 remaining items

  9. lionel- commented on Feb 19, 2026

    @lionel-
    Contributor

    I'm going to move this to go with #7176 for the additional work to support package developers working with compiled code.

    The main purpose of this issue is for R level work though. The current default method of installation produces dangling R srcrefs, which degrades the debugging experience.

    That's especially important when working through a stack of vertically integrated packages as load_all() is typically used on a single package.

    When working on a single package, load_all() does load srcrefs during devlopment. However it's also useful to debug a package during normal usage, for instance when dogfooding before release. In that case installing with srcrefs makes the experience a lot better.

  10. jennybc commented on Feb 19, 2026

    @jennybc
    Member

    It feels like this is basically covered by the already-made move to optionally install with R CMD INSTALL and #11875.

  11. lionel- commented on Feb 19, 2026

    @lionel-
    Contributor

    @jennybc Do we have a sense of timeline for the next release of devtools? I guess what I'm suggesting is that we make base the default if the devtools release is on a longer timeline (e.g. 4 or 6 months). If it's released within the next months then it'd be fine to wait. It just seems very cheap for us to make base the default though.

    I'm thinking about this in the framework of the debugger work that we're finalising for the March release.

  12. jennybc commented on Feb 19, 2026

    @jennybc
    Member

    We want to do a devtools release very soon! I'm happy to commit to a very short timelines and just get 'er done to unblock Positron.

  13. lionel- commented on Feb 19, 2026

    @lionel-
    Contributor

    Perfect!

  14. jennybc commented on Apr 23, 2026

    @jennybc
    Member

    Will be solved when we do #11875

  15. added a commit that references this issue on Jun 3, 2026
    a991e89
  16. locked as resolved and limited conversation to collaborators on Jun 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions