rjdverse / rjdemetra

R interface to JDemetra+ v 2.x
https://rjdverse.github.io/rjdemetra
52 stars 16 forks source link

Error in reading java methods #116

Closed TanguyBarthelemy closed 1 year ago

TanguyBarthelemy commented 1 year ago

I'm trying to translate some java call with $ into .jcall call.

For example, I'm working with a workspace created by JDemetra+ v2.2.4 :

library("RJDemetra")
library("rJava")

ws <- RJDemetra::load_workspace("WS/ws_output.xml")
mp <- ws |> RJDemetra::get_object(3)
sa_item <- mp3 |> RJDemetra::get_object(3)

Then I can get the SA defintion of my SA-ITEM and the included metadata

jt <- .jcall(x, "Ljd2/datatypes/sa/SaItemType;", "getSaDefinition")
metadata <- jt$getMetaData()

But with a .jcall call, I only have errors and I don't succeed to access the same object:

metadata2 <- .jcall(jt, "Lec/tstoolkit/MetaData;", "getMetaData")
> Error in .jcall(jt, "Lec/tstoolkit/MetaData;", "getMetaData") : 
>   method getMetaData with signature ()Lec/tstoolkit/MetaData; not found

Did I forget something or (as usual), am I using the wrong version of my R packages / the v2 java core routines ?

Thank you !

(the purpose behind this is to fix bugs in rjdworkspace::get_comment function)

AQLT commented 1 year ago

It is because you are using the wrong class for the output. You can use the function .jmethods to see the methods associated to a type of object and the output:

library(RJDemetra)
library(rJava)
ws <- new_workspace()
mp <- new_multiprocessing(ws, "sa1")
add_sa_item(ws, "sa1", x13(ipi_c_eu[, 1]), "X13")
sa_item <- ws |> RJDemetra::get_object(1) |> RJDemetra::get_object(1)
jt <- .jcall(sa_item, "Ljd2/datatypes/sa/SaItemType;", "getSaDefinition")
metadata <- jt$getMetaData()
.jmethods(jt, "getMetaData")
#> [1] "public java.util.Map jd2.datatypes.sa.SaItemType.getMetaData()"
metadata2 <- .jcall(jt, "Ljava/util/Map;", "getMetaData")
TanguyBarthelemy commented 1 year ago

Thank you Alain a lot ! This .jmethods function is very magical !