stefan-m-lenz / JuliaConnectoR

A functionally oriented interface for calling Julia from R
Other
100 stars 6 forks source link

How to use broadcasted density functions? #27

Closed danielinteractive closed 9 months ago

danielinteractive commented 9 months ago

Hi @stefan-m-lenz ,

thank you and your co-authors for this great package!

One small question: I was trying to use a broadcasted density method, and did not really understand why it failed.

Reprex:

library(JuliaConnectoR)
Distributions <- juliaImport("Distributions")
f <- Distributions$Beta(2, 1)
juliaEval("using Distributions")
juliaCall("pdf", f, 0.2) # works
juliaCall("pdf.", f, seq(0, 1, 100))

where the last call fails with:

Original Julia error message:
MethodError: no method matching (::Main.RConnector.var"#27#30"{Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, typeof(pdf)})(::Beta{Float64}, ::Float64)

Closest candidates are:
  (::Main.RConnector.var"#27#30")(::Any)
   @ Main.RConnector ~/R/x86_64-pc-linux-gnu-library/4.3/JuliaConnectoR/Julia/reading.jl:361

Session info:

R version 4.3.1 (2023-06-16)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.6 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0 
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale:
 [1] LC_CTYPE=de_DE.UTF-8       LC_NUMERIC=C               LC_TIME=de_CH.UTF-8       
 [4] LC_COLLATE=de_DE.UTF-8     LC_MONETARY=de_CH.UTF-8    LC_MESSAGES=de_DE.UTF-8   
 [7] LC_PAPER=de_CH.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=de_CH.UTF-8 LC_IDENTIFICATION=C       

time zone: Europe/Luxembourg
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] JuliaConnectoR_1.1.2

loaded via a namespace (and not attached):
[1] compiler_4.3.1 tools_4.3.1 
stefan-m-lenz commented 9 months ago

Thanks for reaching out! This looks like a bug. I could reproduce it and I have to investigate it further.

Broadcasting is supposed to work as you had expected.

For single arguments, it works:

juliaCall("sin.", seq(0,10,1)*pi)

There is probably a bug with multiple arguments.

stefan-m-lenz commented 9 months ago

The fix for this bug is now included in release 1.1.3, which is also available on CRAN. Thanks again for reporting!

danielinteractive commented 9 months ago

Super, thanks @stefan-m-lenz !