Skip to content

Commit

Permalink
option to re-execute Rprofile on session resume
Browse files Browse the repository at this point in the history
Merge branch 'feature/rprofile-on-resume'
  • Loading branch information
jjallaire committed Sep 15, 2012
2 parents 30647c3 + 077db44 commit 0b31b6a
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 13 deletions.
4 changes: 3 additions & 1 deletion src/cpp/r/include/r/session/RSession.hpp
Expand Up @@ -49,7 +49,8 @@ struct ROptions
serverMode(false),
autoReloadSource(false),
restoreWorkspace(true),
saveWorkspace(SA_SAVEASK)
saveWorkspace(SA_SAVEASK),
rProfileOnResume(false)
{
}
core::FilePath userHomePath;
Expand All @@ -70,6 +71,7 @@ struct ROptions
bool autoReloadSource ;
bool restoreWorkspace;
SA_TYPE saveWorkspace;
bool rProfileOnResume;
};

struct RInitInfo
Expand Down
3 changes: 2 additions & 1 deletion src/cpp/r/session/REmbedded.hpp
Expand Up @@ -61,7 +61,8 @@ struct InternalCallbacks

void runEmbeddedR(const core::FilePath& rHome,
const core::FilePath& userHome,
bool newSession,
bool quiet,
bool loadInitFile,
SA_TYPE defaultSaveAction,
const Callbacks& callbacks,
InternalCallbacks* pInternal);
Expand Down
7 changes: 4 additions & 3 deletions src/cpp/r/session/REmbeddedPosix.cpp
Expand Up @@ -46,7 +46,8 @@ namespace session {

void runEmbeddedR(const core::FilePath& /*rHome*/, // ignored on posix
const core::FilePath& /*userHome*/, // ignored on posix
bool newSession,
bool quiet,
bool loadInitFile,
SA_TYPE defaultSaveAction,
const Callbacks& callbacks,
InternalCallbacks* pInternal)
Expand Down Expand Up @@ -102,11 +103,11 @@ void runEmbeddedR(const core::FilePath& /*rHome*/, // ignored on posix
Rstart Rp = &rp;
R_DefParams(Rp) ;
Rp->R_Slave = FALSE ;
Rp->R_Quiet = newSession ? FALSE : TRUE;
Rp->R_Quiet = quiet ? TRUE : FALSE;
Rp->R_Interactive = TRUE ;
Rp->SaveAction = defaultSaveAction ;
Rp->RestoreAction = SA_NORESTORE; // handled within initialize()
Rp->LoadInitFile = newSession ? TRUE : FALSE;
Rp->LoadInitFile = loadInitFile ? TRUE : FALSE;
R_SetParams(Rp) ;

// redirect console
Expand Down
7 changes: 4 additions & 3 deletions src/cpp/r/session/REmbeddedWin32.cpp
Expand Up @@ -315,7 +315,8 @@ void setMemoryLimit()

void runEmbeddedR(const core::FilePath& rHome,
const core::FilePath& userHome,
bool newSession,
bool quiet,
bool loadInitFile,
SA_TYPE defaultSaveAction,
const Callbacks& callbacks,
InternalCallbacks* pInternal)
Expand Down Expand Up @@ -343,11 +344,11 @@ void runEmbeddedR(const core::FilePath& rHome,
// more configuration
pRP->CharacterMode = RGui;
pRP->R_Slave = FALSE;
pRP->R_Quiet = newSession ? FALSE : TRUE;
pRP->R_Quiet = quiet ? TRUE : FALSE;
pRP->R_Interactive = TRUE;
pRP->SaveAction = defaultSaveAction;
pRP->RestoreAction = SA_NORESTORE;
pRP->LoadInitFile = newSession ? TRUE : FALSE;
pRP->LoadInitFile = loadInitFile ? TRUE : FALSE;

// hooks
pRP->ReadConsole = callbacks.readConsole;
Expand Down
11 changes: 8 additions & 3 deletions src/cpp/r/session/RSession.cpp
Expand Up @@ -1176,8 +1176,12 @@ Error run(const ROptions& options, const RCallbacks& callbacks)
r::routines::addCallMethod(createUUIDMethodDef);

// run R
bool newSession = restartContext().hasSessionState()
|| !s_suspendedSessionPath.exists();
bool loadInitFile = restartContext().hasSessionState()
|| !s_suspendedSessionPath.exists()
|| options.rProfileOnResume;

bool quiet = s_suspendedSessionPath.exists();

r::session::Callbacks cb;
cb.showMessage = RShowMessage;
cb.readConsole = RReadConsole;
Expand All @@ -1193,7 +1197,8 @@ Error run(const ROptions& options, const RCallbacks& callbacks)
cb.cleanUp = RCleanUp;
r::session::runEmbeddedR(FilePath(rLocations.homePath),
options.userHomePath,
newSession,
quiet,
loadInitFile,
s_options.saveWorkspace,
cb,
&s_internalCallbacks);
Expand Down
2 changes: 2 additions & 0 deletions src/cpp/session/SessionMain.cpp
Expand Up @@ -2546,6 +2546,8 @@ int main (int argc, char * const argv[])
rOptions.autoReloadSource = options.autoReloadSource();
rOptions.restoreWorkspace = restoreWorkspaceOption();
rOptions.saveWorkspace = saveWorkspaceOption();
rOptions.rProfileOnResume = serverMode &&
userSettings().rProfileOnResume();

// r callbacks
r::session::RCallbacks rCallbacks;
Expand Down
5 changes: 4 additions & 1 deletion src/cpp/session/SessionOptions.cpp
Expand Up @@ -150,7 +150,10 @@ core::ProgramStatus Options::read(int argc, char * const argv[])
"session preflight script")
("session-create-public-folder",
value<bool>(&createPublicFolder_)->default_value(false),
"automatically create public folder");
"automatically create public folder")
("session-rprofile-on-resume-default",
value<bool>(&rProfileOnResumeDefault_)->default_value(false),
"default user setting for running Rprofile on resume");

// r options
bool rShellEscape; // no longer works but don't want to break any
Expand Down
12 changes: 12 additions & 0 deletions src/cpp/session/SessionUserSettings.cpp
Expand Up @@ -41,6 +41,7 @@ const char * const kAgreementHash = kAgreementPrefix "agreedToHash";
const char * const kAutoCreatedProfile = "autoCreatedProfile";
const char * const kUiPrefs = "uiPrefs";
const char * const kAlwaysRestoreLastProject = "restoreLastProject";
const char * const kRProfileOnResume = "rprofileOnResume";
const char * const kSaveAction = "saveAction";
const char * const kLoadRData = "loadRData";
const char * const kInitialWorkingDirectory = "initialWorkingDirectory";
Expand Down Expand Up @@ -318,6 +319,17 @@ void UserSettings::setAlwaysRestoreLastProject(bool alwaysRestore)
settings_.set(kAlwaysRestoreLastProject, alwaysRestore);
}

bool UserSettings::rProfileOnResume() const
{
return settings_.getBool(kRProfileOnResume,
session::options().rProfileOnResumeDefault());
}

void UserSettings::setRprofileOnResume(bool rProfileOnResume)
{
settings_.set(kRProfileOnResume, rProfileOnResume);
}

int UserSettings::saveAction() const
{
return settings_.getInt(kSaveAction, -1);
Expand Down
3 changes: 3 additions & 0 deletions src/cpp/session/include/session/SessionOptions.hpp
Expand Up @@ -110,6 +110,8 @@ class Options : boost::noncopyable

bool createPublicFolder() const { return createPublicFolder_; }

bool rProfileOnResumeDefault() const { return rProfileOnResumeDefault_; }

unsigned int minimumUserId() const { return 100; }

core::FilePath coreRSourcePath() const
Expand Down Expand Up @@ -298,6 +300,7 @@ class Options : boost::noncopyable
std::string preflightScript_;
int timeoutMinutes_;
bool createPublicFolder_;
bool rProfileOnResumeDefault_;

// r
std::string coreRSourcePath_;
Expand Down
3 changes: 3 additions & 0 deletions src/cpp/session/include/session/SessionUserSettings.hpp
Expand Up @@ -92,6 +92,9 @@ class UserSettings : boost::noncopyable
std::string defaultLatexProgram() const;
bool alwaysEnableRnwCorcordance() const;

bool rProfileOnResume() const;
void setRprofileOnResume(bool rProfileOnResume);

bool alwaysRestoreLastProject() const;
void setAlwaysRestoreLastProject(bool alwaysRestore);

Expand Down
5 changes: 4 additions & 1 deletion src/cpp/session/modules/SessionWorkbench.cpp
Expand Up @@ -183,18 +183,20 @@ Error setPrefs(const json::JsonRpcRequest& request, json::JsonRpcResponse*)

// read and set general prefs
int saveAction;
bool loadRData;
bool loadRData, rProfileOnResume;
std::string initialWorkingDir;
error = json::readObject(generalPrefs,
"save_action", &saveAction,
"load_rdata", &loadRData,
"rprofile_on_resume", &rProfileOnResume,
"initial_working_dir", &initialWorkingDir);
if (error)
return error;

userSettings().beginUpdate();
userSettings().setSaveAction(saveAction);
userSettings().setLoadRData(loadRData);
userSettings().setRprofileOnResume(rProfileOnResume);
userSettings().setInitialWorkingDirectory(FilePath(initialWorkingDir));
userSettings().endUpdate();

Expand Down Expand Up @@ -342,6 +344,7 @@ Error getRPrefs(const json::JsonRpcRequest& request,
json::Object generalPrefs;
generalPrefs["save_action"] = userSettings().saveAction();
generalPrefs["load_rdata"] = userSettings().loadRData();
generalPrefs["rprofile_on_resume"] = userSettings().rProfileOnResume();
generalPrefs["initial_working_dir"] = module_context::createAliasedPath(
userSettings().initialWorkingDirectory());

Expand Down
Expand Up @@ -20,10 +20,12 @@ protected GeneralPrefs() {}

public static final native GeneralPrefs create(int saveAction,
boolean loadRData,
boolean rProfileOnResume,
String initialWorkingDir) /*-{
var prefs = new Object();
prefs.save_action = saveAction;
prefs.load_rdata = loadRData;
prefs.rprofile_on_resume = rProfileOnResume;
prefs.initial_working_dir = initialWorkingDir;
return prefs ;
}-*/;
Expand All @@ -36,6 +38,10 @@ public native final int getSaveAction() /*-{
public native final boolean getLoadRData() /*-{
return this.load_rdata;
}-*/;

public native final boolean getRprofileOnResume() /*-{
return this.rprofile_on_resume;
}-*/;

public native final String getInitialWorkingDirectory() /*-{
return this.initial_working_dir;
Expand Down
Expand Up @@ -127,6 +127,11 @@ public void onClick(ClickEvent event)
spaced(removeHistoryDuplicates_);
add(removeHistoryDuplicates_);

rProfileOnResume_ = new CheckBox("Run Rprofile when resuming suspended session");
spaced(rProfileOnResume_);
if (!Desktop.isDesktop())
add(rProfileOnResume_);

cranMirrorTextBox_ = new TextBoxWithButton(
"CRAN mirror:",
"Change...",
Expand Down Expand Up @@ -194,6 +199,7 @@ public void execute(String encoding)
dirChooser_.setEnabled(false);
alwaysSaveHistory_.setEnabled(false);
removeHistoryDuplicates_.setEnabled(false);
rProfileOnResume_.setEnabled(false);
cranMirrorTextBox_.setEnabled(false);
restoreLastProject_.setEnabled(false);
}
Expand Down Expand Up @@ -236,6 +242,9 @@ protected void initialize(RPrefs rPrefs)
alwaysSaveHistory_.setValue(historyPrefs.getAlwaysSave());
removeHistoryDuplicates_.setValue(historyPrefs.getRemoveDuplicates());

rProfileOnResume_.setValue(generalPrefs.getRprofileOnResume());
rProfileOnResume_.setEnabled(true);

// packages prefs
PackagesPrefs packagesPrefs = rPrefs.getPackagesPrefs();
cranMirrorTextBox_.setEnabled(true);
Expand Down Expand Up @@ -285,6 +294,7 @@ public boolean onApply(RPrefs rPrefs)
// set general prefs
GeneralPrefs generalPrefs = GeneralPrefs.create(saveAction,
loadRData_.getValue(),
rProfileOnResume_.getValue(),
dirChooser_.getText());
rPrefs.setGeneralPrefs(generalPrefs);

Expand Down Expand Up @@ -335,6 +345,7 @@ private void setEncoding(String encoding)
private CRANMirror cranMirror_ = CRANMirror.empty();
private TextBoxWithButton cranMirrorTextBox_;
private CheckBox restoreLastProject_;
private CheckBox rProfileOnResume_;
private final SourceServerOperations server_;
private final UIPrefs prefs_;
private final TextBoxWithButton encoding_;
Expand Down

0 comments on commit 0b31b6a

Please sign in to comment.