rbytecode icon indicating copy to clipboard operation
rbytecode copied to clipboard

Specific bytecode does not work

Open abs-xyz opened this issue 1 year ago • 0 comments

library(compiler)

f <- function() require(compiler)
f() # no output, expected
s <- disq(function() require(compiler)) |> as.character()
eval(asm(s))() # Error in if (!loaded) { : the condition has length > 1

require looks like this

require <- function (package, lib.loc = NULL, quietly = FALSE, warn.conflicts, 
    character.only = FALSE, mask.ok, exclude, include.only, attach.required = missing(include.only)) 
{
    if (!character.only) 
        package <- as.character(substitute(package))
    loaded <- paste0("package:", package) %in% search()
    if (!loaded) {        # ERROR here!
        if (!quietly)
...

loaded might be a vector, but its length is 1 in the above invocation.

Tried to reproduce this with a simpler version, but it does not produce that error somehow

s2 <- disq(function (package, character.only = FALSE)  
{
    if (!character.only) 
        package <- as.character(substitute(package))
    loaded <- paste0("package:", package) %in% search()
    if (!loaded) { print("no!") }
}) |> as.character()
eval(asm(s3))(compiler) # fine

Tried on R4.2.2 and R4.4.2.


Any ideas on what might the issue be?

I suspect this would have to do with the behavior of promises

abs-xyz avatar Dec 21 '24 09:12 abs-xyz