-
Notifications
You must be signed in to change notification settings - Fork 11
proof of concept for attaching :doc metadata to generate functions #98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
behrica
wants to merge
27
commits into
scicloj:master
Choose a base branch
from
behrica:helpToDoc
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 23 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
87a2591
proof of concept for attaching :doc metadata to genarte functions
behrica 07b6189
extrcated help into own ns to avoid repetion and cyclic dependencies
behrica 4b4d162
aaded a global flag (default off), which controls if help is attached
behrica 66feb0f
refcatored and added tests
behrica 0c78839
Merge branch 'master' of https://github.com/scicloj/clojisr into help…
behrica 0a1bf37
moved test
behrica 42ad811
made tests more robust
behrica ec67fc7
make memoize work
behrica 0df3e68
fixed syntax error in Dockerfile
behrica 5a830cb
fixed apt get
behrica b74e11d
updated jsd version to fix CI build
behrica 8d38dc0
postpone help attaching va future
behrica 09d129f
fixed tests
behrica 3ea82e6
refactored help->:doc and use alter-meta! to set it in a future, always
behrica 435da76
commented one failing test , as :doc is now present on vars
behrica 55cebf7
Merge branch 'master' of github.com:scicloj/clojisr into helpToDoc
behrica 5447897
use one thred per required librray
behrica 510dc54
use build packages for test
behrica a4c03c0
replace future by using java Thread
behrica b8f1920
merged with master
behrica 2b09025
use daemon thread
behrica 2708928
remove returned symbol
behrica 8a40ceb
Merge branch 'master' into helpToDoc
behrica ef1fcc9
introduced flag to generate-doc-strings
behrica 91f78e9
Merge branch 'master' of https://github.com/scicloj/clojisr into help…
behrica 6b8a3e9
added doc-string to 'require-r'
behrica 62e5513
addedd a few tests for requirer
behrica File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,3 +18,4 @@ pom.xml.asc | |
| .clay* | ||
| *qmd | ||
| .clerk | ||
| .calva | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| (ns clojisr.v1.help | ||
| (:require [clojisr.v1.eval :as evl] | ||
| [clojisr.v1.using-sessions :as using-sessions] | ||
| [clojisr.v1.impl.java-to-clj :as java2clj] | ||
| [clojure.string :as str] | ||
| [clojisr.v1.session :as session] | ||
|
|
||
| [clojisr.v1.help :as help])) | ||
| (defn- un-back-quote [s] | ||
| (str/replace s "`" "" )) | ||
|
|
||
|
|
||
| (defn _get-help[function package] | ||
| ;(println :obtain-help (format "%s/%s " (name package) (un-back-quote (name function)))) | ||
| (->> | ||
| (evl/r (format | ||
| "tryCatch(capture.output(tools:::Rd2txt(utils:::.getHelpFile(as.character(help(%s,%s))), options=list(underline_titles=FALSE))),error=function(e) {return( \"no doc available\")})" | ||
| (name function) (name package)) | ||
| (session/fetch-or-make nil)) | ||
|
|
||
| (using-sessions/r->java) | ||
| (java2clj/java->clj) | ||
| (str/join "\n"))) | ||
|
|
||
| (def get-help (memoize _get-help)) | ||
|
|
||
| (defn help | ||
|
|
||
| "Gets help for an R object or function" | ||
| ([r-object] | ||
| (let [symbol (second (re-find #"\{(.*)\}" (:code r-object))) | ||
| split (str/split symbol #"::")] | ||
|
|
||
| (get-help (second split) (first split) ))) | ||
|
|
||
| ) | ||
|
|
||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,6 +96,8 @@ | |
| (recur threaded (next forms))) | ||
| x))) | ||
|
|
||
|
|
||
|
|
||
| (comment | ||
| (-|> 4 | ||
| :+ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| (ns clojisr.v1.help-test | ||
| (:require | ||
| [clojure.string :as str] | ||
| [clojure.test :refer [is deftest]] | ||
| [clojisr.v1.r :as r])) | ||
|
|
||
| (r/require-r '[stats]) | ||
| (Thread/sleep 5000) | ||
|
|
||
|
|
||
| (deftest help-docstring | ||
| (r/require-r '[stats]) | ||
| (Thread/sleep 5000) | ||
| (is (str/starts-with? | ||
| (:doc (meta (var r.stats/lm))) | ||
| "Fitting Linear"))) | ||
|
|
||
| (deftest help-function | ||
| (is (str/starts-with? | ||
| (r/help "lm" "stats") | ||
| "Fitting Linear"))) | ||
|
|
||
| (deftest require-defauls-should-not-throws-exception | ||
|
|
||
| ; should not crash | ||
| (r/require-r '[base]) | ||
| (r/require-r '[stats]) | ||
| (r/require-r '[utils]) | ||
| (r/require-r '[graphics]) | ||
| (r/require-r '[datasets])) | ||
|
|
||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In rich packages you'll run zillions of threads. The whole loop should be run in one thread.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tried this before, in a future.
That introduced a "noticeble lack" when evaluating:
(r/require-r '[base])
(r/require-r '[stats])
(unless we put a Thread/sleep in the beginning. See comments above)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found a trick.....
So we do the slow reading of the help 'on demand'
This works in vscode.
the value of the :doc is now not a string, but a function , implementing "toString".
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I asked about this on slack, let's see.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a good idea it seems, and I somehow agree.