scicloj / clojisr

Clojure speaks statistics - a bridge between Clojure to R
https://scicloj.github.io/clojisr/
Eclipse Public License 2.0
150 stars 10 forks source link

Fix R symbols/names -> clojure symbols/keywords conversion #13

Closed genmeblog closed 4 years ago

genmeblog commented 4 years ago

We have two places where R symbol conversion is applied.

  1. Named list keys are converted to keywords
  2. R library symbols are converted to Clojure symbols.

Both keys and symbols can be invalid in various ways in Clojure so proper conversion should be made.

Strategy is:

  1. Convert invalid names (keys) to a string
  2. Skip invalid symbols (like "[[<-.factor") or wrap into dedicated function (like brabra)

For both cases we use #"[\Q[](){}#@;:,\/^'~\"\E].*"` which catches only first letter as forbidden letter.

Two regexes should be prepared for each cases separately and tested against real names taken from R libraries (mainly base).

daslu commented 4 years ago

Related discussion:

https://clojurians.zulipchat.com/#narrow/stream/204621-r-interop/topic/names

https://clojurians.zulipchat.com/#narrow/stream/204621-r-interop/topic/access.20to.20dataframes

genmeblog commented 4 years ago

I think it should be still open since it doesn't catch different cases like this:

(->> "list(A=1,B=2,'123#strange<text> ()'=3)"
     r
     r->clj)
;; => {:A [1.0], :B [2.0], :123#strange<text> () [3.0]}