Skip to content

keep source without recompiling ? #753

Open

Description

@moodymudskipper

I would love to be able to see original formatting and comments for every package I install.

This can be done by installing from source with "--with-keep.source" :

install.packages(package,  type = "source", INSTALL_opts = c("--with-keep.source"))`

But installing from source takes forever in some cases, so I don't love it as a default.

Would there be a way to install from binary, yet fetch the code from the .tar.gz. and have the code available at a minor installation cost?

Nowadays disk space is cheap enough, it doesn't make a lot of sense anymore to strip the source of IMO, so this might even be the default?

Activity

  1. gaborcsardi commented on Mar 8, 2025

    @gaborcsardi
    Member

    Seems like this is possible:

    src <- "f <- function() 1+\n2+\n3"
    eval(parse(text = src, keep.source = FALSE))
    e <- new.env()
    eval(parse(text = src, keep.source = TRUE), envir = e)
    f2 <- e$f
    
    f
    #> function () 
    #> 1 + 2 + 3
    f2
    #> function() 1+
    #> 2+
    #> 3
    #> <environment: 0x13b9dd048>
    f <- compiler::cmpfun(f)
    .Internal(bodyCode(f))
    #> <bytecode: 0x13ccb33d0>
    
    attr(f, "srcref") <- attr(f2, "srcref")
    .Internal(bodyCode(f))
    #> <bytecode: 0x13ccb33d0>
    f
    #> function() 1+
    #> 2+
    #> 3
    #> <bytecode: 0x13ccb33d0>

    Created on 2025-03-08 with reprex v2.1.0

    I don't know where the source code is stored in the installed package, though.

    It is not really clear to me how we would add the source references to all functions (S4, R6 class methods, etc.) systematically.

  2. added
    feature
    on May 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions