Query the script engine for current variables

9 views
Skip to first unread message

Per Nyfelt

unread,
Dec 19, 2018, 3:09:25 AM12/19/18
to Renjin
Hi,

Is there a way to ask the ScritpEngine for its current environment i.e. what variables and functions that have been defined similar to how the Environment tab in RStudio for GNU R?

I tried to follow the docs at http://docs.renjin.org/en/latest/library/capture.html but no joy:

Renjin 0.9.2716
Copyright (C) 2018 The R Foundation for Statistical Computing
Copyright (C) 2018 BeDataDriven
> d <- "bla"
> str(svmfit)
Error: object 'svmfit' not found
> 

Best regards,
Per

Bertram, Alexander

unread,
Dec 19, 2018, 4:36:23 AM12/19/18
to renji...@googlegroups.com
Hi Per,
The example you cite assumes the previous statements in the document have been evaluated:
engine.eval("library(e1071)");
    engine.eval("data(iris)");
    engine.eval("svmfit <- svm(Species~., data=iris)");

To get a list of variables defined in the global environment, you use the ls() function:

StringVector variables = (StringVector)engine.eval("ls()");

You can also access the global Environment object through Renjin's API:
RenjinScriptEngine renjinScriptEngine = (RenjinScriptEngine)engine;
Session session = renjinScriptEngine.getSession();
Environment global = session.getGlobalEnvironment();

Hope this helps,
Alex


--
You received this message because you are subscribed to the Google Groups "Renjin" group.
To unsubscribe from this group and stop receiving emails from it, send an email to renjin-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Alex Bertram
Technical Director
bedatadriven

Web: http://bedatadriven.com
Tel. Nederlands: +31(0)647205388
Skype: akbertram

Per Nyfelt

unread,
Dec 19, 2018, 5:14:58 AM12/19/18
to Renjin
Yes it helps, thanks for the explanation!

I've submitted a pull request to that docs page with the info you provided.

Best regards,
Per
Reply all
Reply to author
Forward
0 new messages