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

ERROR: invalid redefinition of constant with R library #418

Closed
gaballench opened this issue May 24, 2021 · 4 comments · Fixed by #532
Closed

ERROR: invalid redefinition of constant with R library #418

gaballench opened this issue May 24, 2021 · 4 comments · Fixed by #532

Comments

@gaballench
Copy link

Hello!

I am trying to load the r package ape from within julia using RCall.

It fails when trying to load it with the @rlibrary macro:

julia> @rlibrary ape
ERROR: invalid redefinition of constant node_depth_edgelength
Stacktrace:
 [1] top-level scope
   @ none:1
 [2] eval
   @ ./boot.jl:360 [inlined]
 [3] rimport(pkg::String, s::Symbol; normalizenames::Bool)
   @ RCall ~/.julia/packages/RCall/3mHXJ/src/namespaces.jl:41
 [4] rimport
   @ ~/.julia/packages/RCall/3mHXJ/src/namespaces.jl:22 [inlined]
 [5] rimport (repeats 2 times)
   @ ~/.julia/packages/RCall/3mHXJ/src/namespaces.jl:46 [inlined]
 [6] top-level scope
   @ ~/.julia/packages/RCall/3mHXJ/src/namespaces.jl:95

however, it works when calling library inside an R string (i.e., using R""):

julia> R"library(ape)"
RObject{StrSxp}
[1] "ape"       "stats"     "graphics"  "grDevices" "utils"     "datasets" 
[7] "methods"   "base"     

My guess is that something happens when loading ape's namespace but I don't understand why the macro fails while the R string does not. I have been unable to find a similar case in earlier issues.

Thanks in advance,

Gustavo

@palday
Copy link
Collaborator

palday commented Jul 16, 2024

I'm able to replicate on recent Julia, R and RCall:

julia> versioninfo()
Julia Version 1.10.4
Commit 48d4fd48430 (2024-06-04 10:41 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin22.4.0)
  CPU: 8 × Apple M1
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, apple-m1)
Threads: 1 default, 0 interactive, 1 GC (on 4 virtual cores)

julia> using Pkg; Pkg.status()
Status `/private/var/folders/yy/nyj87tsn7093bb7d84rl64rh0000gp/T/jl_LF3K4R/Project.toml`
  [6f49c342] RCall v0.14.1

julia> reval("version")
RObject{VecSxp}
               _                           
platform       aarch64-apple-darwin20.0.0  
arch           aarch64                     
os             darwin20.0.0                
system         aarch64, darwin20.0.0       
status                                     
major          4                           
minor          3.3                         
year           2024                        
month          02                          
day            29                          
svn rev        86002                       
language       R                           
version.string R version 4.3.3 (2024-02-29)
nickname       Angel Food Cake 

@palday
Copy link
Collaborator

palday commented Jul 16, 2024

@rlibrary actually calls rimport which does a little bit more than just reval("library(...)").

If we disable name normalization, then things seem to work:

julia> ape = rimport("ape"; normalizenames=false)
Main.__anonymous__

julia> using .ape

julia> node_depth_edgelength
RObject{VecSxp}
$name
[1] "node_depth_edgelength"

$address
<pointer: 0x6000010dbd60>
attr(,"class")
[1] "RegisteredNativeSymbol"

$dll
DLL name: ape
Filename:
        /Users/palday/.julia/conda/3/aarch64/lib/R/library/ape/libs/ape.dylib
Dynamic lookup: FALSE

$numParameters
[1] 5

attr(,"class")
[1] "CRoutine"         "NativeSymbolInfo"

But that actually hiding the real problem: ape defines both node_depth_edgelength and node.depth.edgelength. Normalization converts . in R names to _ in Julia, thus creating a name collision.

@ararslan
Copy link
Member

I wonder if normalizenames should actually be false by default given that Julia identifiers can contain arbitrary characters if defined and referenced using var"".

@palday
Copy link
Collaborator

palday commented Jul 17, 2024

@ararslan That would be a breaking change (which I'm not adverse to), but I would like to gather a few more breaking changes first.

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

Successfully merging a pull request may close this issue.

3 participants