Skip to content

Commit

Permalink
Worked on windows installer and added code to throw R errors as JS ex…
Browse files Browse the repository at this point in the history
…ceptions so that the error messages show up in JS error console.
  • Loading branch information
gmbecker committed Jan 6, 2013
1 parent 126e983 commit 2eb7de6
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 13 deletions.
4 changes: 4 additions & 0 deletions inst/NPAPI/Makefile.win
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

resource.o:
windres resource.rc resource.o

1 change: 1 addition & 0 deletions inst/NPAPI/WebR.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,5 @@ SEXP doGetVar(NPIdentifier name, NPP inst);
void* doRLookup(void *in);
bool doNamedCall(NPP inst, SEXP fun, const NPVariant *argsIn, uint32_t count, NPVariant *_res, NPNetscapeFuncs *funcs);
convert_t GetConvertBehavior(NPVariant *var, NPP inst, NPNetscapeFuncs *funcs);
void ThrowRError(NPObject *obj, NPNetscapeFuncs *funcs);
#endif // WebR.h
2 changes: 2 additions & 0 deletions inst/NPAPI/WebREngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ bool WebREngine::Invoke(NPIdentifier name, const NPVariant *args, uint32_t argCo
SETCAR(call, Rf_install("parseEval"));
SETCAR(CDR(call), Rargs[0]);
PROTECT(ans = rQueue.requestRCall(call, R_GlobalEnv, &error, this->instance));

addProt = 2;
}
else if (name == myNPNFuncs->getstringidentifier("namedArgsCall"))
Expand Down Expand Up @@ -222,6 +223,7 @@ bool WebREngine::Invoke(NPIdentifier name, const NPVariant *args, uint32_t argCo
ConvertRToNP(ans, this->instance, myNPNFuncs, result, convert);
else
{
ThrowRError(this, myNPNFuncs);
fprintf(stderr, "\n Error: R function call failed.");fflush(stderr);
ConvertRToNP(R_NilValue, this->instance, myNPNFuncs, result, CONV_DEFAULT);
}
Expand Down
3 changes: 2 additions & 1 deletion inst/NPAPI/WebRFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ bool RFunction::InvokeDefault(const NPVariant *args, uint32_t argCount, NPVarian
//If it's an error, just throw an error for the browser.
//else
// ConvertRToNP(R_NilValue, this->instance, this->funcs, result, false);

else
ThrowRError(this, this->funcs);
UNPROTECT(argCount + addProt);

return !error;
Expand Down
20 changes: 19 additions & 1 deletion inst/NPAPI/WebRMutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ void* doRCall(void * in)

PROTECT( ans = R_tryEval(toeval, env, err));
if(*err)
ans = R_NilValue;
{

ans = R_NilValue;
}
else
{
if(TYPEOF(ans) == PROMSXP)
Expand Down Expand Up @@ -243,3 +246,18 @@ void RCallQueue::init()

}

void ThrowRError(NPObject *obj, NPNetscapeFuncs *funcs)
{
int err;
SEXP errcall, errsxp;
PROTECT(errcall = allocVector(LANGSXP, 1));
SETCAR(errcall, Rf_install("geterrmessage"));
PROTECT(errsxp = R_tryEval(errcall, R_GlobalEnv, &err));
int len = strlen(CHAR(STRING_ELT(errsxp, 0)));
NPUTF8 *errmsg = malloc(len*sizeof(char));
strcpy(errmsg, CHAR(STRING_ELT(errsxp, 0)));

funcs->setexception(obj, errmsg);
UNPROTECT(2);

}
105 changes: 105 additions & 0 deletions inst/NPAPI/WinInstallerScript.iss
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "RBrowserPlugin"
#define MyAppVersion "0.9"
#define MyAppPublisher "Gabriel Becker"
#define MyAppURL "http://www.omegahat.org/RBrowserPlugin"

[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{47529F3D-851C-45F7-9FEF-C49164125A2F}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppName}
LicenseFile=C:\Users\gmbecker\Documents\GitHub\RFirefox\inst\NPAPI\liscense.txt
OutputDir=C:\Users\gmbecker\Documents\GitHub\RFirefox\inst\NPAPI\WinInstaller
OutputBaseFilename=RBrowserPluginSetup
Compression=lzma
SolidCompression=yes
;ArchitecturesInstallIn64BitMode=x64

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
Name: "brazilianportuguese"; MessagesFile: "compiler:Languages\BrazilianPortuguese.isl"
Name: "catalan"; MessagesFile: "compiler:Languages\Catalan.isl"
Name: "czech"; MessagesFile: "compiler:Languages\Czech.isl"
Name: "danish"; MessagesFile: "compiler:Languages\Danish.isl"
Name: "dutch"; MessagesFile: "compiler:Languages\Dutch.isl"
Name: "finnish"; MessagesFile: "compiler:Languages\Finnish.isl"
Name: "french"; MessagesFile: "compiler:Languages\French.isl"
Name: "german"; MessagesFile: "compiler:Languages\German.isl"
Name: "greek"; MessagesFile: "compiler:Languages\Greek.isl"
Name: "hebrew"; MessagesFile: "compiler:Languages\Hebrew.isl"
Name: "hungarian"; MessagesFile: "compiler:Languages\Hungarian.isl"
Name: "italian"; MessagesFile: "compiler:Languages\Italian.isl"
Name: "japanese"; MessagesFile: "compiler:Languages\Japanese.isl"
Name: "norwegian"; MessagesFile: "compiler:Languages\Norwegian.isl"
Name: "polish"; MessagesFile: "compiler:Languages\Polish.isl"
Name: "portuguese"; MessagesFile: "compiler:Languages\Portuguese.isl"
Name: "russian"; MessagesFile: "compiler:Languages\Russian.isl"
Name: "serbiancyrillic"; MessagesFile: "compiler:Languages\SerbianCyrillic.isl"
Name: "serbianlatin"; MessagesFile: "compiler:Languages\SerbianLatin.isl"
Name: "slovenian"; MessagesFile: "compiler:Languages\Slovenian.isl"
Name: "spanish"; MessagesFile: "compiler:Languages\Spanish.isl"
Name: "ukrainian"; MessagesFile: "compiler:Languages\Ukrainian.isl"

[Files]
Source: "C:\Users\gmbecker\Documents\GitHub\RFirefox\inst\NPAPI\npRBrowserPlugin.dll"; DestDir: "{app}"; Flags: ignoreversion
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Icons]
Name: "{group}\{cm:ProgramOnTheWeb,{#MyAppName}}"; Filename: "{#MyAppURL}"
Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"

[Registry]
;Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueName: "R_HOME"; ValueData: {reg:HKLM\Software\R-Core\R, InstallPath}; ValueType: string; Flags: createvalueifdoesntexist uninsdeletevalue;
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueName: "R_HOME"; ValueData: {code:RLoc}; ValueType: string; Flags: createvalueifdoesntexist uninsdeletevalue;
Root: HKLM; Subkey: "Software\MozillaPlugins\@R/RBrowserPlugin"; ValueType: string; Flags: uninsdeletekey;
Root: HKLM; Subkey: "Software\MozillaPlugins\@R/RBrowserPlugin"; ValueName: "Path"; ValueData: "{app}\npRBrowserPlugin.dll"; ValueType: string;
Root: HKLM; Subkey: "Software\MozillaPlugins\@R/RBrowserPlugin"; ValueName: "Description"; ValueData: "R Browser Plugin"; ValueType: string;
Root: HKLM; Subkey: "Software\MozillaPlugins\@R/RBrowserPlugin\MimeTypes"; ValueType: string; Flags: uninsdeletekey;
Root: HKLM; Subkey: "Software\MozillaPlugins\@R/RBrowserPlugin\MimeTypes\application/r"; ValueType: string; Flags: uninsdeletekey;
Root: HKLM; Subkey: "Software\MozillaPlugins\@R/RBrowserPlugin\MimeTypes\application/test-r"; ValueType: string; Flags: uninsdeletekey;

[Code]
var
RHomePage: TInputDirWizardPage;
procedure InitializeWizard;
begin
RHomePage := CreateInputDirPage(wpSelectDir,
'Select R_HOME Location', 'Where is the R installation which should be used by the plugin?',
'Select the folder in which the R installation to be used by the plugin is located, then click Next.',
False, '');
RHomePage.Add('');
RHomePage.Values[0] := ExpandConstant('{code:RLocFromReg}');
end;
function RLoc(Param: String): String;
begin
Result := RHomePage.Values[0];
end;
function RLocFromReg(Param: String): String;
begin
if IsWin64 then
begin
RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Wow6432Node\R-core\R',
'InstallPath', Result);
end
else
begin
RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\R-core\R',
'InstallPath', Result);
end;
end;
21 changes: 12 additions & 9 deletions inst/examples/exLinkedPlot.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<head>
<!--
<script type="text/javascript" src="http://github.com/DmitryBaranovskiy/raphael/raw/master/raphael.js"> </script>
-->
-->
<script type="text/javascript" src="../javascript/raphael.js"> </script>

<script type="text/javascript" src="../javascript/Rhelpers.js"> </script>
Expand All @@ -12,21 +12,24 @@
# library(RFirefox)
thing = raphaelCDev("raphcanvas")
plot(mtcars$hp, mtcars$mpg, xlab = "HP", ylab="MPG", main = "MtCars Hp vs Mpg", cex=3)

thing2 = raphaelCDev("raphcanvas2")
plot(mtcars$wt, mtcars$qsec, xlab = "WT", ylab ="QSEC", main = "MtCars Wt vs Qsec", cex=3)
pts = thing$getPoints()
pts2 = thing2$getPoints()

addHandlers = function(pts)
{
sapply(1:length(pts), function(i)
sapply(1:length(pts), function(i)
{
force(i)
#pts[[i]]$hover(function() colorIt(i), function() unColorIt(i))
nd = pts[[i]][["node"]]
nd$addEventListener("mouseover", function(e) colorIt(i), convertArgs = c(TRUE, FALSE))
nd$addEventListener("mouseout", function(e) unColorIt(i), convertArgs = c(TRUE, FALSE))

#nd$addEventListener("mouseover", function(e) colorIt(i), convertArgs = c(TRUE, FALSE))
#nd$addEventListener("mouseout", function(e) unColorIt(i), convertArgs = c(TRUE, FALSE))
nd$addEventListener("mouseover", function(e) colorIt(i))
nd$addEventListener("mouseout", function(e) unColorIt(i))

TRUE
} )
return(TRUE)
Expand All @@ -37,21 +40,21 @@
{
pts[[i]]$attr("fill", "ff0000")
pts2[[i]]$attr("fill", "ff0000")

}

unColorIt = function(i)
{
pts[[i]]$attr("fill", "#ffffff")
pts2[[i]]$attr("fill", "#ffffff")

}
addHandlers(pts)
addHandlers(pts2)
</script>
</head>
<body>
<embed id="REngine" type="application/test-r" height="0" width="0"></embed>
<embed id="REngine" type="application/test-r" height="0" width="0"></embed>
<div>
<div id="raphcanvas" height="200" width="150" />
<div id="raphcanvas2" height="200" width="150" style="float:right;" />
Expand Down
24 changes: 24 additions & 0 deletions inst/tests/Rplatform.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<html>
<script type="text/javascript" src = "../javascript/Rhelpers.js"></script>
<head>
<script type="text/R">
getplat = function() sessionInfo()$platform
</script>
<script type="text/javascript">
function getplatform()
{
var res = R.getplat();
alert(res);
var div = document.getElementById("mydiv");
div.innerHTML = res;
}
</script>

</head>
<body>
<embed type="application/test-r" width="0" height="0"></embed>
<input type="button" onclick="getplatform();"/>
<div id="mydiv" ></div>

</body>
</html>
8 changes: 6 additions & 2 deletions src/Makevars.win
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ EXTRAFLAGS=$(RFIREFOX_DEF) -fPIC
PKG_CPPFLAGS=-I ../inst/NPAPI/ -I ../inst/npapi-sdk-headers/
PKG_LIBS=
#SHLIBCMD= C:/R64/bin/x64/Rcmd SHLIB BasicPlugin.cpp WebREngine.cpp NPConversions.cpp WebRObject.cpp WebRFunction.cpp WebRMutex.cpp --output=npRBrowserPlugin.dll
SHLIBCMD= C:/R64/bin/i386/Rcmd SHLIB defs.def BasicPlugin.cpp WebREngine.cpp NPConversions.cpp WebRObject.cpp WebRFunction.cpp WebRMutex.cpp resource.o --output=npRBrowserPlugin.dll

#SHLIBCMD= C:/R64/bin/i386/Rcmd SHLIB defs.def BasicPlugin.cpp WebREngine.cpp NPConversions.cpp WebRObject.cpp WebRFunction.cpp WebRMutex.cpp resource.o --output=npRBrowserPlugin.dll
ifeq "$(WIN)" "64"
SHLIBCMD=
else
SHLIBCMD=$(R_HOME)/bin$(R_ARCH_BIN)/Rcmd SHLIB defs.def BasicPlugin.cpp WebREngine.cpp NPConversions.cpp WebRObject.cpp WebRFunction.cpp WebRMutex.cpp resource.o --output=npRBrowserPlugin.dll
endif
.PHONY: all

all: $(SHLIB) extension
Expand Down

0 comments on commit 2eb7de6

Please sign in to comment.