Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keep source without recompiling ? #753

Open
moodymudskipper opened this issue Mar 8, 2025 · 1 comment
Open

keep source without recompiling ? #753

moodymudskipper opened this issue Mar 8, 2025 · 1 comment

Comments

@moodymudskipper
Copy link

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?

@gaborcsardi
Copy link
Member

gaborcsardi commented Mar 8, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants