Skip to content

Commit

Permalink
Merge pull request #1037 from africanmathsinitiative/master
Browse files Browse the repository at this point in the history
merge from main
  • Loading branch information
dannyparsons authored Feb 7, 2020
2 parents d4b643d + 6a14b18 commit 6492776
Show file tree
Hide file tree
Showing 9 changed files with 377 additions and 145 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,5 @@ ModelManifest.xml
/instat/static/InstatObject/R/.RData
/instat/static/InstatObject/R/examples_R6.R
/instat/static/InstatObject/R/.Rhistory
/instat/static/InstatObject/R/examples.R
/instat/static/InstatObject/R/examples.R
installer/Output/
19 changes: 17 additions & 2 deletions Instat.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
# Visual Studio 15
VisualStudioVersion = 15.0.28307.1000
MinimumVisualStudioVersion = 10.0.40219.1
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "instat", "instat\instat.vbproj", "{D62FCDDB-1E9E-4B63-B7AA-6482343C9736}"
EndProject
Expand All @@ -10,15 +10,30 @@ EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D62FCDDB-1E9E-4B63-B7AA-6482343C9736}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D62FCDDB-1E9E-4B63-B7AA-6482343C9736}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D62FCDDB-1E9E-4B63-B7AA-6482343C9736}.Debug|x64.ActiveCfg = Debug|x64
{D62FCDDB-1E9E-4B63-B7AA-6482343C9736}.Debug|x64.Build.0 = Debug|x64
{D62FCDDB-1E9E-4B63-B7AA-6482343C9736}.Debug|x86.ActiveCfg = Debug|Any CPU
{D62FCDDB-1E9E-4B63-B7AA-6482343C9736}.Debug|x86.Build.0 = Debug|Any CPU
{D62FCDDB-1E9E-4B63-B7AA-6482343C9736}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D62FCDDB-1E9E-4B63-B7AA-6482343C9736}.Release|Any CPU.Build.0 = Release|Any CPU
{D62FCDDB-1E9E-4B63-B7AA-6482343C9736}.Release|x64.ActiveCfg = Release|x64
{D62FCDDB-1E9E-4B63-B7AA-6482343C9736}.Release|x64.Build.0 = Release|x64
{D62FCDDB-1E9E-4B63-B7AA-6482343C9736}.Release|x86.ActiveCfg = Release|Any CPU
{D62FCDDB-1E9E-4B63-B7AA-6482343C9736}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {95E05758-FE41-459A-B394-5B505DC51688}
EndGlobalSection
EndGlobal
55 changes: 55 additions & 0 deletions installer/Installer_Generation_Guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Installer Generation Guide

To generate the installer for R-Instat with R bundled inside and all the R packages pre-installed requires a few steps.

## Step 1: Build R-Instat from Visual Studio

You will have to repeat this step for generating 32 bit and 64 bit binaries.
- In Visual Studio open the R-Instat solution.
- To the left of the Start button are two dropdowns.
- Select Release for the first dropdown
- Select x86 for 32 bit build, and x64 for 64 bit build.
- Check that clsRLink.vb is pointing to the version of R you plan to bundle
```
Private strRBundledVersion As String = "3.6.2"
```

## Step 2: Generate Bundled R Install

Once you have built release binaries of R-Instat:
1. Open cmd.exe as an Administrator
2. cd to the the bin folder with the Release binaries. It will probably look similar to C:/Users/YourName/source/repos/R-Instat/instat/bin/Release
or for 64 bit /R-Instat/instat/bin/x64/Release
3. Then cd into the static folder (e.g R-Instat/instat/bin/Release/static)
4. Download the R installer EXE from (https://cran.r-project.org/bin/windows/base/R-3.6.2-win.exe) and save into this directory
5. Run the installer using
```
R-3.6.2-win.exe /DIR="./R-3.6.2"
```
6. Go through the install process. Choose custom install and deselect either 32 bit or 64 bit. (If you're building for 32 bit then exclude 64 bit).

## Step 3: Install R packages inside bundled R

1. Cd into the R folder you just installed ./R-3.6.2/bin
2. Run R.exe
3. Run the install_bundled_packages.R script in the same folder as this Readme.
4. The ncdf4.helpers package required a custom version, you can download it from here: https://drive.google.com/file/d/1UqwqVDxMvlHNocUa0i6uiGFT24zwGdgB/view?usp=sharing
Once you've downloaded that zip file, extract the ncdf4.helpers folder into the ./R-3.6.2/library folder

## Step 4: Build Installer EXE using Inno Setup

1. Install Inno Setup from here: https://www.jrsoftware.org/isdl.php
2. Scroll down and select innosetup-6.0.3.exe (or a newer version)
3. Open the Inno Script Compiler from the start menu
4. From the file menu choose open
5. Then navigate to the inno_install_script_32bit.iss script (or 64 bit version) in the same folder as this readme.
6. From the top menu choose compile.
7. The installer should be in installer/Output folder

## Bundling a newer version of R

If you want to bundle a newer version of R (after discussing with the team the consequences of that) you'll need to change the following files:
- clsRLink.vb
- inno_install_script_32bit.iss
- inno_install_script_36bit.iss
- Installer_Generation_Guide.md
40 changes: 40 additions & 0 deletions installer/inno_install_script_32bit.iss
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
; Script generated by the Inno Script Studio Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

[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={{4263A8D4-1068-45F9-A542-C340C4A22E8B}
AppName=R-Instat
#define AppVerName "0.56"
AppVersion={#AppVerName}
AppPublisher=African Maths Institute
AppPublisherURL=http://r-instat.org/
AppSupportURL=http://r-instat.org/
AppUpdatesURL=http://r-instat.org/
DefaultDirName={autopf}\R-Instat\{#AppVerName}
DefaultGroupName=R-Instat
AllowNoIcons=yes
OutputBaseFilename=R-Instat_{#AppVerName}_Installer_32
SetupIconFile=..\instat\Resources\rinstat_icon_Hih_icon.ico
Compression=lzma
SolidCompression=yes

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 0,6.1

[Files]
Source: "..\instat\bin\Release\instat.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\instat\bin\Release\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Icons]
Name: "{group}\R-Instat"; Filename: "{app}\instat.exe"
Name: "{group}\{cm:UninstallProgram,R-Instat}"; Filename: "{uninstallexe}"
Name: "{commondesktop}\R-Instat"; Filename: "{app}\instat.exe"; Tasks: desktopicon
Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\R-Instat"; Filename: "{app}\instat.exe"; Tasks: quicklaunchicon

[Run]
Filename: "{app}\instat.exe"; Description: "{cm:LaunchProgram,R-Instat}"; Flags: nowait postinstall skipifsilent
41 changes: 41 additions & 0 deletions installer/inno_install_script_64bit.iss
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
; Script generated by the Inno Script Studio Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

[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={{4263A8D4-1068-45F9-A542-C340C4A22E8B}
AppName=R-Instat
#define AppVerName "0.56"
AppVersion={#AppVerName}
AppPublisher=African Maths Institute
AppPublisherURL=http://r-instat.org/
AppSupportURL=http://r-instat.org/
AppUpdatesURL=http://r-instat.org/
DefaultDirName={autopf}\R-Instat\{#AppVerName}
DefaultGroupName=R-Instat
AllowNoIcons=yes
OutputBaseFilename=R-Instat_{#AppVerName}_Installer_64
SetupIconFile=..\instat\Resources\rinstat_icon_Hih_icon.ico
Compression=lzma
SolidCompression=yes
ArchitecturesInstallIn64BitMode=x64

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 0,6.1

[Files]
Source: "..\instat\bin\x64\Release\instat.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\instat\bin\x64\Release\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Icons]
Name: "{group}\R-Instat"; Filename: "{app}\instat.exe"
Name: "{group}\{cm:UninstallProgram,R-Instat}"; Filename: "{uninstallexe}"
Name: "{commondesktop}\R-Instat"; Filename: "{app}\instat.exe"; Tasks: desktopicon
Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\R-Instat"; Filename: "{app}\instat.exe"; Tasks: quicklaunchicon

[Run]
Filename: "{app}\instat.exe"; Description: "{cm:LaunchProgram,R-Instat}"; Flags: nowait postinstall skipifsilent
25 changes: 25 additions & 0 deletions installer/install_bundled_packages.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
install.packages("miniCRAN")

core_pkgs <- c("reshape2", "lubridate","plyr", "dplyr", "rtf", "openxlsx", "ggplot2",
"extRemes", "GGally", "agridat", "FactoMineR", "plotrix", "candisc", "R6",
"openair", "circular", "survival", "Evapotranspiration", "clifro", "devtools",
"factoextra", "circlize", "CircStats", "gridExtra", "ggfortify", "rio",
"readxl", "lme4", "dummies", "ggthemes", "lazyeval", "stringr", "httr",
"jsonlite", "fitdistrplus", "visreg", "climdex.pcic", "mosaic", "ncdf4",
"getPass", "RMySQL", "DBI", "EnvStats", "signmedian.test", "sjPlot",
"sjmisc", "plotly", "svglite", "htmlTable", "rje", "tidyr", "faraway",
"ncdf.tools", "rrefine", "dae", "gapminder", "questionr", "nycflights13",
"Lahman", "RcppRoll", "cmsaf", "sjlabelled", "maptools", "RColorBrewer",
"colorRamps", "mapdata", "rworldmap", "rworldxtra", "e1071", "robustbase",
"wakefield", "Hmisc", "SPEI", "agricolae", "sf", "weathermetrics",
"geosphere", "ggmosaic", "readODS", "ggalt", "ggpmisc", "treemapify",
"hydroGOF", "hydroTSM", "verification", "DescTools",
"PCICt", "abind") # Added because of ncdf4.helpers
# You must unzip ncdf4.helpers folder into library folder manually
# Download from here https://drive.google.com/file/d/1UqwqVDxMvlHNocUa0i6uiGFT24zwGdgB/view?usp=sharing

pkgList <- miniCRAN::pkgDep(core_pkgs, type = "win.binary", repos = "https://cran.rstudio.com/",
suggests = FALSE, includeBasePkgs = TRUE, Rversion = "3.6")

install.packages(pkgList, lib = "../library",
repos = "https://cran.rstudio.com/")
66 changes: 51 additions & 15 deletions instat/clsRLink.vb
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,48 @@ Public Class RLink
Private iWaitDelay As Integer = 2

Private strRVersionMajorRequired As String = "3"
Private strRVersionMinorRequired As String = "6"
Private strRVersionMinorRequired As String = "6"
Private strRVersionRequired As String = strRVersionMajorRequired & "." & strRVersionMinorRequired & ".0"
Private strRBundledVersion As String = "3.6.2"

Public Function StartREngine(Optional strScript As String = "", Optional iCallType As Integer = 0, Optional strComment As String = "", Optional bSeparateThread As Boolean = True) As Boolean
Public Function StartREngine(Optional strScript As String = "", Optional iCallType As Integer = 0, Optional strComment As String = "", Optional bSeparateThread As Boolean = True) As Boolean
Dim strMissingPackages() As String
Dim expTemp As SymbolicExpression
Dim strMajor As String = ""
Dim strMinor As String = ""
Dim iCurrentCallType As Integer
Dim bClose As Boolean = False
Dim strStaticPath = Path.GetFullPath("static")
Dim rHome = Path.Combine(strStaticPath, "R-" & strRBundledVersion)
Dim cpuArchitectureFolder = "i386"

Try
REngine.SetEnvironmentVariables()
' Get R .NET to use bundled R in static folder
' This static folder is added as a part of the install process as described in
' installer/Installer_Generation_Guide.md
'
If Environment.Is64BitProcess Then
cpuArchitectureFolder = "x64"
End If
Dim rPath = Path.Combine(rHome, "bin", cpuArchitectureFolder)
Console.WriteLine("R Home: " & rHome)
Console.WriteLine("R Path: " & rPath)

' Use bundled R if included
If Directory.Exists(rHome) And Directory.Exists(rPath) Then
Console.WriteLine("Using bundled R")
REngine.SetEnvironmentVariables(rPath, rHome)
Else
' Use normal process for finding local R if bundled version not included
REngine.SetEnvironmentVariables()
End If

clsEngine = REngine.GetInstance()
clsEngine.Initialize()
Catch ex As Exception
' Modified message since currently we recommend use of R version 3.6.0
MsgBox(ex.Message & Environment.NewLine & "Could not establish connection to R." & vbNewLine & "R-Instat requires version " & strRVersionMajorRequired & "." & strRVersionMinorRequired & ".0 of R." & vbNewLine & "Note that R-Instat does not work with R below 3.5.0. We recommend using R 3.6.0. Try reruning the installation to install R 3.6.0 or download R 3.6.0 from https://cran.r-project.org/bin/windows/base/old/3.6.0/ and restart R-Instat." & vbNewLine & ex.Message, MsgBoxStyle.Critical, "Cannot initialise R connection.")
Application.Exit()
' Modified message since currently we recommend use of same R version as bundled version
MsgBox(ex.Message & Environment.NewLine & "Could not establish connection to R." & vbNewLine & "R-Instat requires version " & strRVersionRequired & " of R." & vbNewLine & "Note that R-Instat does not work with R below 3.5.0. We recommend using R " & strRBundledVersion & ". Try reruning the installation to install R " & strRBundledVersion & " or download R " & strRBundledVersion & " from https://cran.r-project.org/bin/windows/base/old/" & strRBundledVersion & "/ and restart R-Instat." & vbNewLine & ex.Message, MsgBoxStyle.Critical, "Cannot initialise R connection.")
Application.Exit()
Environment.Exit(0)
End Try
Try
Expand All @@ -91,22 +115,30 @@ Public Class RLink
strMajor = expTemp.AsCharacter(0)
End If
expTemp = RunInternalScriptGetValue("R.Version()$minor", bSilent:=True)
If expTemp IsNot Nothing AndAlso expTemp.Type <> Internals.SymbolicExpressionType.Null Then
strMinor = expTemp.AsCharacter(0)
End If
If strMinor.Count >= 3 Then
If expTemp IsNot Nothing AndAlso expTemp.Type <> Internals.SymbolicExpressionType.Null Then
strMinor = expTemp.AsCharacter(0)
End If
Dim strRVersionRunning = strMajor & "." & strMinor
If strMinor.Count >= 3 Then
If Not (strMajor = strRVersionMajorRequired AndAlso strMinor.Count > 0 AndAlso strMinor(0) >= strRVersionMinorRequired) Then
MsgBox("Your current version of R is outdated. You are currently running R version: " & strMajor & "." & strMinor & vbNewLine & "R-Instat requires at least version " & strRVersionMajorRequired & "." & strRVersionMinorRequired & ".0 or greater." & vbNewLine & "Try reruning the installation to install an updated version of R or download R from https://cran.r-project.org/bin/windows/base/ and restart R-Instat.", MsgBoxStyle.Critical, "R Version not supported.")
Application.Exit()
MsgBox("Your current version of R is outdated. You are currently running R version: " & strRVersionRunning & vbNewLine &
"R-Instat requires at least version " & strRVersionRequired & " or greater." &
vbNewLine & "Try reruning the installation to install an updated version of R or download R from " &
"https://cran.r-project.org/bin/windows/base/" & strRVersionRequired & "and restart R-Instat.", MsgBoxStyle.Critical, "R Version not supported.")
Application.Exit()
Environment.Exit(0)
End If
Else
MsgBox("Could not determine version of R installed on your machine. R-Instat requires version: " & strRVersionMajorRequired & "." & strRVersionMinorRequired & ".0." & vbNewLine & "Try uninstalling any versions of R and rerun the installation to install R 3.6.0 or download R 3.6.0 from https://cran.r-project.org/bin/windows/base/old/3.6.0/ and restart R-Instat.", MsgBoxStyle.Critical, "R Version error.")
Application.Exit()
MsgBox("Could not determine version of R installed on your machine. R-Instat requires version: " & strRVersionRequired & vbNewLine &
"Try uninstalling any versions of R and rerun the installation to install R " & strRVersionRequired & " or download R " &
strRVersionRequired & "From https://cran.r-project.org/bin/windows/base/old/" & strRVersionRequired &
"And restart R-Instat.", MsgBoxStyle.Critical, "R Version error.")
Application.Exit()
Environment.Exit(0)
End If
Catch ex As Exception
MsgBox(ex.Message & Environment.NewLine & "Could not determine the version of R installed on your machine. We recommend rerunning the installation to install an updated version of R or download the latest version from https://cran.r-project.org/ and restart R-Instat.", MsgBoxStyle.Critical, "Cannot determine R version.")

Application.Exit()
Environment.Exit(0)
End Try
Expand All @@ -115,6 +147,7 @@ Public Class RLink
strScript = GetRSetupScript()
iCallType = 0
strComment = "Setting working directory, sourcing R code and loading R packages"

bSeparateThread = True
End If
For Each strLine As String In strScript.Split(Environment.NewLine)
Expand Down Expand Up @@ -163,6 +196,7 @@ Public Class RLink
clsEngine.Dispose()
Catch ex As Exception
MsgBox("Could not dispose for the connection to R" & Environment.NewLine & ex.Message, MsgBoxStyle.Exclamation, "Cannot close R connection.")

End Try
End If
End Sub
Expand Down Expand Up @@ -427,6 +461,7 @@ Public Class RLink
End If
Catch ex As Exception
'MsgBox("Could not add script to auto save log file at:" & frmMain.strAutoSaveLogFilePath & Environment.NewLine & ex.Message, MsgBoxStyle.Exclamation, "Auot save Log File")

bAutoSaveLogExists = False
Finally
bFirstLogCode = False
Expand Down Expand Up @@ -490,7 +525,8 @@ Public Class RLink
If Not bSuccess Then
Evaluate("graphics.off()", bSilent:=bSilent, bSeparateThread:=bSeparateThread, bShowWaitDialogOverride:=bShowWaitDialogOverride)
strGraphDisplayOption = "view_R_viewer"
MsgBox("A problem occured saving graphs in the temporary location: " & strTempGraphsDirectory & vbNewLine & vbNewLine & "To ensure graphs can still be viewed, graphs will now appear in a pop up R viewer." & vbNewLine & "Restarting R-Instat and/or your machine usually resolves this. You can change this setting back in Tools > Options: 'Graph Display' if this later becomes resolved.", MsgBoxStyle.Exclamation)
MsgBox("A problem occured saving graphs in the temporary location " & strTempGraphsDirectory & vbNewLine & vbNewLine & "To ensure graphs can still be viewed, graphs will now appear in a pop up R viewer." & vbNewLine & "Restarting R-Instat and/or your machine usually resolves this. You can change this setting back in Tools > Options: 'Graph Display' if this later becomes resolved.", MsgBoxStyle.Exclamation)

End If
'need to boost resolution of the devices, it's not as good as with ggsave.
End If
Expand Down
Loading

0 comments on commit 6492776

Please sign in to comment.