Skip to content

Commit

Permalink
first attempt of help function
Browse files Browse the repository at this point in the history
  • Loading branch information
behrica committed Nov 8, 2021
1 parent 8922a1c commit fb27a72
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/clojisr/v1/r.clj
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,24 @@
(defonce ^:private shutdown-hook-registered
(do (.addShutdownHook (Runtime/getRuntime) (Thread. #(locking session/sessions (discard-all-sessions))))
true))


(defn help
"Gets help for an R object or function"
([r-object]
(let [symbol (second (re-find #"\{(.*)\}" (:code r-object)))
split (string/split symbol #"::")]

(help (second split) (first split))))

([function package]
(->>
(r (format "capture.output(tools:::Rd2txt(utils:::.getHelpFile(as.character(help(%s,%s))), options=list(underline_titles=FALSE)))" (name function) (name package)))
r->clj
(string/join "\n"))))


(defn print-help
"Prints help for an R object or function"
([r-object] (println (help r-object)))
([function package] (println (help function package))))

0 comments on commit fb27a72

Please sign in to comment.