Skip to content

Commit 61375d9

Browse files
committed
test refactor wip + partially named list fix
1 parent e547f21 commit 61375d9

12 files changed

Lines changed: 429 additions & 309 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# Change Log
22
All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/).
33

4+
## [unreleased]
5+
- all operators are added
6+
- support for `switch` in codegen
7+
- `vrkrasana` moved out of `src` (also `vrkrasana` branch is created)
8+
- set of not used or internal functions deprecated in the main namespace (`function`, `apply-function`, `print-help`, `str-md`, `println-r-lines`, `r-lines->md`, `println-captured-str`)
9+
- `object-structure` - function returning result of `utils::str` as a string.
10+
- fixed: partially named list conversion to a map had wrong id for unnamed values
11+
412
## [1.1.0]
513
- added more operators `%/%`, `%%` ,`%in%`, `xor`
614
- use devcontainer setup following template

src/clojisr/v1/codegen.clj

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,15 @@
124124
[vs session ctx]
125125
(let [[pred f1 f2] (map #(form->code % session ctx) (take 3 vs))]
126126
(if f2
127-
(format "if(%s) {%s} else {%s}" pred f1 f2)
127+
(format "if(%s) {%s} else {%s}" pred f1 f2)
128128
(format "if(%s) {%s}" pred f1))))
129129

130+
(defn switch->code
131+
"Create switch"
132+
[vs session ctx]
133+
(let [forms (map #(form->code % session ctx) (take 3 vs))]
134+
(format "switch(%s)" (join "," forms))))
135+
130136
(defn for-loop->code
131137
"Create for loop"
132138
[bindings body session ctx]
@@ -232,6 +238,7 @@
232238
(= "do" fs) (format "{%s}" (join ";" (map #(form->code % session ctx) r)))
233239
(= "for" fs) (for-loop->code (first r) (rest r) session ctx)
234240
(= "while" fs) (while-loop->code (first r) (rest r) session ctx)
241+
(= "switch" fs) (switch->code r session ctx)
235242
(contains? bracket-data fs) (bracket-call->code (bracket-data fs) r session ctx)
236243
(= 'clojure.core/unquote f) (unquote-form->code r session ctx)
237244
:else (symbol-form->code fs r session ctx)))

src/clojisr/v1/functions.clj

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424
(let [autorefreshing (refresh/auto-refresing-object
2525
r-object)]
2626
(fn ([& args]
27-
(let [explicit-session-args
28-
(when (some-> args butlast last (= :session-args))
29-
(last args))]
30-
(apply-function
31-
@autorefreshing
32-
(if explicit-session-args
33-
(-> args butlast butlast)
34-
args)
35-
(session/fetch-or-make explicit-session-args))))))))
27+
(let [explicit-session-args
28+
(when (some-> args butlast last (= :session-args))
29+
(last args))]
30+
(apply-function
31+
@autorefreshing
32+
(if explicit-session-args
33+
(-> args butlast butlast)
34+
args)
35+
(session/fetch-or-make explicit-session-args))))))))
3636

3737
(defn function
3838
[r-object]

src/clojisr/v1/help.clj

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,22 @@
66
[clojisr.v1.session :as session]
77

88
[clojisr.v1.help :as help]))
9+
910
(defn- un-back-quote [s]
1011
(str/replace s "`" "" ))
1112

1213

1314
(defn _get-help[function package]
14-
;(println :obtain-help (format "%s/%s " (name package) (un-back-quote (name function))))
15-
(->>
16-
(evl/r (format
17-
"tryCatch(capture.output(tools:::Rd2txt(utils:::.getHelpFile(as.character(help(%s,%s))), options=list(underline_titles=FALSE))),error=function(e) {return( \"no doc available\")})"
18-
(name function) (name package))
19-
(session/fetch-or-make nil))
20-
21-
(using-sessions/r->java)
22-
(java2clj/java->clj)
23-
(str/join "\n")))
15+
;(println :obtain-help (format "%s/%s " (name package) (un-back-quote (name function))))
16+
(->>
17+
(evl/r (format
18+
"tryCatch(capture.output(tools:::Rd2txt(utils:::.getHelpFile(as.character(help(%s,%s))), options=list(underline_titles=FALSE))),error=function(e) {return( \"no doc available\")})"
19+
(name function) (name package))
20+
(session/fetch-or-make nil))
21+
22+
(using-sessions/r->java)
23+
(java2clj/java->clj)
24+
(str/join "\n")))
2425

2526
(def get-help (memoize _get-help))
2627

src/clojisr/v1/impl/clj_to_java.clj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
[tech.v3.dataset.protocols :as ds-prot]
55
[tech.v3.dataset.column :as col]
66
[tech.v3.dataset :as dataset]
7-
[tech.v3.datatype :as dtype]
8-
[tech.v3.dataset :as ds])
7+
[tech.v3.datatype :as dtype])
98
(:import [clojisr.v1.robject RObject]))
109

1110
(declare clj->java)

src/clojisr/v1/impl/common.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"Create key names for partially named lists"
3838
[names]
3939
(map-indexed (fn [^long id k]
40-
(if (empty? k) id (usually-keyword k))) names))
40+
(if (empty? k) (inc id) (usually-keyword k))) names))
4141

4242
;; REXP/SEXP helpers for dataset conversion
4343

@@ -52,8 +52,8 @@
5252
prot/RProto
5353
(inherits? [_ _] false)
5454
prot/Clojable
55-
(->clj [obj] obj)
56-
(->native [obj] obj))
55+
(->clj [_] nil)
56+
(->native [_] nil))
5757

5858
(defn ->seq-with-missing
5959
[xs missing]

src/clojisr/v1/impl/rserve/printing.clj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
(prot/eval-r->java session))]
1111
(->> (.asStrings output)
1212
(string/join "\n"))))
13+

src/clojisr/v1/impl/rserve/rexp.clj

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
valid-list-names]]
66
[clojisr.v1.impl.types :as types])
77
(:import (org.rosuda.REngine REXP REXPDouble REXPInteger REXPLogical REXPString REXPFactor REXPSymbol REXPNull
8-
REXPUnknown REXPGenericVector REXPList
8+
REXPLanguage REXPUnknown REXPGenericVector REXPList
99
RFactor RList)))
1010

1111
;;;;;;;;;;;;;;;;;;;;
@@ -97,6 +97,12 @@
9797
(->column [exp _] (prot/->clj exp)) ;; same as above
9898
(->columns [exp] (list->columns exp)))
9999

100+
;; probably needs to be treated differently...
101+
(extend-type REXPLanguage
102+
prot/Clojable
103+
(->clj [exp] (list->map-or-vector exp prot/->clj))
104+
(->native [exp] (list->map-or-vector exp prot/->native)))
105+
100106
;;;;;;;;;;;;;;;;;;;;
101107
;; Clojure -> REXP
102108
;;;;;;;;;;;;;;;;;;;;
@@ -130,6 +136,6 @@
130136
(REXPGenericVector. (REXPList. nil))))
131137

132138
(defn ->rexp-named-list [^java.util.Collection ks
133-
^java.util.Collection vs]
139+
^java.util.Collection vs]
134140
(-> (RList. vs ks)
135141
(REXPGenericVector.))) ;; named list creates attr already

src/clojisr/v1/impl/rserve/session.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
port (or port (get-free-port))
105105
rserve (when spawn-rserve?
106106
(proc/start-rserve port init-r))]
107-
107+
108108
(when rserve ;; be sure the process is spawned
109109
(loop [attempts (int 5)]
110110
(Thread/sleep 500)

0 commit comments

Comments
 (0)