Skip to content

Commit 6aff303

Browse files
committed
add preserved_refs
1 parent dfe9c7c commit 6aff303

File tree

7 files changed

+206
-69
lines changed

7 files changed

+206
-69
lines changed

.vscode/settings.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"files.associations": {
3+
"functional": "c"
4+
}
5+
}

NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ S3method("jl",integer)
2020
S3method("jl",double)
2121
S3method("jl",logical)
2222
S3method("jl",character)
23+
S3method("jl",factor)
2324

2425
S3method("names",jlStruct)
2526
S3method("[",jlStruct)

R/jl_dataframe.R

+21-4
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,32 @@ names.DataFrame <- function(jlval) jlcallR("names",jlval)
1111
jlcall("getindex",jlval, i, jl_symbol(field))
1212
} else NULL
1313
}
14+
1415
"$.DataFrame" <- function(jlval, field) jlval[field]
1516

17+
toR.DataFrame <- function(jlval) {
18+
nms <- toR(jlcall("names",jlval))
19+
res <- list()
20+
for(nm in nms) {
21+
res[[nm]] <- jlcallR("getindex",jlval, jl_colon(), jl_symbol(nm))
22+
}
23+
attr(res,"row.names") <- as.character(1:length(res[[1]]))
24+
class(res) <- "data.frame"
25+
res
26+
}
27+
1628
jl.data.frame <- function(df) {
1729
jlusing("DataFrames")
1830
DF <- jlcall("splat",jl("DataFrame"))
19-
jl_args <- jl("[]")
31+
args <- jl("[]")
32+
vars <- list()
33+
pairs <-list()
2034
for( nm in names(df)) {
21-
jlcall("=>",jl_symbol("a"),jl(c(1,2,3)))
22-
df[[nm]]
35+
vars[[nm]] <- jl(df[[nm]])
36+
pairs[[nm]] <- jlcall("=>",jl_symbol(nm), vars[[nm]])
37+
jlcall("push!", args, pairs[[nm]])
2338
}
24-
# jlcall("vcat",jlcall("=>",jl_symbol("a"),jl(c(1,2,3))),jlcall("=>",jl_symbol("b"),jl(c(3,4,1)))) -> jl_args
39+
jl_func1(DF,args) -> jlval
40+
# attr(jlval,"deps") <- list(vars=vars,pairs=pairs)
41+
jlval
2542
}

R/jl_factor.R

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
3+
toR.CategoricalArray <- function(jlval) {
4+
pool <- jl_getfield(jlval,"pool")
5+
res <- jlR_getfield(jlval,"refs")
6+
attr(res,"levels") <- jlcallR("levels",pool)
7+
class(res) <- "factor"
8+
res
9+
}
10+
11+
jl.factor <- function(fa) {
12+
jlusing("CategoricalArrays")
13+
jlcall("categorical",jl(as.character(fa)))
14+
}

R/jltypes.R

+8-23
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@ jl_typeof <- function(jlval) {
1212

1313
is.jlValue <- function(obj) inherits(obj,"jlValue")
1414

15-
print.jlValue <- function(obj, ...) {
16-
# cat(paste(class(obj),collapse=","),":\n",sep="")
17-
# print(toR(obj))
18-
invisible(jlcallR("display",obj))
15+
# print.jlValue <- function(obj, ...) {
16+
# # cat(paste(class(obj),collapse=","),":\n",sep="")
17+
# # print(toR(obj))
18+
# invisible(jlcallR("display",obj))
19+
# }
20+
21+
print.jlValue <- function(jlval, ...) {
22+
invisible(.Call("jl4R_show_preserved_ref", jlval, PACKAGE = "jl4R"))
1923
}
2024

2125
print.jlUnprintable <- function(obj, ...) print.default(obj)
@@ -40,23 +44,4 @@ toR.jlValue <- function(jlval) {
4044
if(is.list(res)) simplify2array(res) else res
4145
}
4246
}
43-
}
44-
45-
toR.DataFrame <- function(jlval) {
46-
nms <- toR(jlcall("names",jlval))
47-
res <- list()
48-
for(nm in nms) {
49-
res[[nm]] <- jlcallR("getindex",jlval, jl_colon(), jl_symbol(nm))
50-
}
51-
attr(res,"row.names") <- as.character(1:length(res[[1]]))
52-
class(res) <- "data.frame"
53-
res
54-
}
55-
56-
toR.CategoricalArray <- function(jlval) {
57-
pool <- jl_getfield(jlval,"pool")
58-
res <- jlR_getfield(jlval,"refs")
59-
attr(res,"levels") <- jlcallR("levels",pool)
60-
class(res) <- "factor"
61-
res
6247
}

R/jlutils.R

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
jl_symbol <- function(field) jl(paste0(":",field))
1+
# jl_symbol <- function(field) jl(paste0(":",field))
2+
jl_symbol <- function(field) {
3+
if(!.jlrunning()) .jlinit()
4+
res <- .External("jl4R_jl_symbol", field, PACKAGE = "jl4R")
5+
res
6+
}
7+
28
jl_colon <- function() jl_unsafe(":")
39
## Struct facility
410

0 commit comments

Comments
 (0)