scicloj / clojisr

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

Preload default packages by default #17

Open genmeblog opened 4 years ago

genmeblog commented 4 years ago

Preload default packages by default, ie: stats, base, graphics, datasets, grDevices, probably more.

awb99 commented 4 years ago

Perhaps you want to do add a configuration map, that fully defines the R environment that you want to have? You even could check, if required packages are installed, and if not, install them. Or you might want to have two functions (load-env config) and (install-load-env config). So in a way instead of needing a R install plus installed packages, you would need only an installed R. You would do something similar to lein project.clj. And you could even make a lein plugin, that would read :clojisr key from project.clj. lein-ring does this for example.

genmeblog commented 4 years ago

The problem here is that you don't know which backend is used. Renjin library installing is different. Also sometimes you want to install using dev_tools or install from other servers than cran. I would leave such configuration on the R side. Anyway load-env config is great idea and could be great.

The original idea is to load all packages which are preloaded by default by R. But it takes time and is not lazy. So I'm not sure if we should do this or not.

awb99 commented 4 years ago

I think what you should do is define a default-config map. And then the user can define his own config map; and on start you would merge the user config with the default config. this way you allow extensibility of packages, and perhaps some other stuff too.

You also might pass custom init namespace to clojisr, similar to how leiningen can initialize a nrepl connection with some namespace and run an init function.

Perhaps also you want to run r init in a future. And the future sets an atom indicating init-complete; and then all R evals would only run after init-complete.

The future approach makes sense when developing models in the repl. Then you can do certain stuff while R us still initializing, and dont have to wait foreer for the app to bootstrap.

Just an idea...

genmeblog commented 4 years ago

Good idea. Let's wait for session management to push this forward.

behrica commented 2 months ago

I would preload these, as R does:

> search()
[1] ".GlobalEnv"        "package:stats"     "package:graphics" 
[4] "package:grDevices" "package:utils"     "package:datasets" 
[7] "package:methods"   "Autoloads"         "package:base" 
genmeblog commented 2 months ago

Good point. The question is how they should be loaded. As :refer :all in clojisr.v1.r namespace or maybe as aliases?

genmeblog commented 1 month ago

If #94 is done, we can't load above upfront...

behrica commented 1 month ago

So maybe a function like load-default-packages makes sense.