Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix Save R session function
saveSession method in RConsoleView
two more methods in RConsoleView for handling commands coming from different actions
change executeCommand accordingly
  • Loading branch information
Valentin Georgiev committed Apr 27, 2012
1 parent e4aa762 commit 10d52a4
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 19 deletions.
3 changes: 1 addition & 2 deletions plugins/net.bioclipse.r.ui/plugin.xml
Expand Up @@ -109,10 +109,9 @@

</menuContribution>
<menuContribution
allPopups="false"
locationURI="toolbar:net.bioclipse.r.ui.views.RConsoleView">
<command
commandId="net.bioclipse.r.ui.saveRSession"
commandId="net.bioclipse.r.ui.SaveRSession"
icon="icons/r_icon.gif"
label="Save R Session"
style="push">
Expand Down
Expand Up @@ -14,12 +14,12 @@
* @authors valyo
*
*/
public class saveRSessionHandler extends AbstractHandler implements IHandler {
public class SaveRSessionHandler extends AbstractHandler implements IHandler {

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
RConsoleView rView = (RConsoleView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("net.bioclipse.r.ui.views.RConsoleView");
rView.execEditorInput("save.image(\".RData\")");
rView.saveSession();
return null;
}

Expand Down
Expand Up @@ -44,29 +44,52 @@ public void run() {

}

public String execEditorInput(String command) {
return executeCommand(command);
}
/*
* Execute the R command - First check if r manager is available.
* Execute the R command typed in the R console
* uses the evalCommand method
*/
@Override
protected String executeCommand( String command ) {
/*
* TODO
* test on Windows and Linux
*/
String returnVal = null;
String[] commands = null;
commands = RunUtil.parseCommand(command);
for (String cmd : commands){
returnVal = r.eval(cmd);
echoCommand(cmd);
printMessage(returnVal);
}
command = RunUtil.parseCommand(command);
if (command.contains("?") || command.contains("install.packages"))
returnVal = evalCommand(command, false);
else
returnVal = evalCommand(command, true);
return returnVal;
}

public void execEditorInput(String command) {
executeCommand(command);
}

/*
* method that calls r.eval and prints the command and the output
*/
protected String evalCommand(String command, boolean quotes) {
String output = null;
if (quotes) {
command = command.replace("\"", "\\\"");
output = r.eval("eval(parse(text =\"" + command + "\"))");
command = command.replace("\\\"", "\"");
echoCommand(command); //echo the whole command
}
else {
output = r.eval(command);
//split command on lines
echoCommand(command); //echo the array of strings
}
if (output.length() != 0) {
printMessage(output);
}
return output;
}

public void saveSession() {
if (r.eval("save.image(\".RData\")") != null)
printMessage(NEWLINE + "R Session saved");
}

private void getRBusinessManager() {
try {
r = Activator.getDefault().getJavaRBusinessManager();
Expand Down

0 comments on commit 10d52a4

Please sign in to comment.