Skip to content

Information for developers

Danny Parsons edited this page Jan 26, 2022 · 8 revisions

Setting up your R environment

  1. Download the version of R currently bundled with R-Instat. You can check the value of strRBundledVersion in clsRLink.vb to find the current version. Download R from CRAN https://cran.r-project.org/bin/windows/base/

  2. Install the R packages required for R-Instat. Do this in R or RStudio. The variable pkgs in install_packages.R defines the list of required R package. Run the line that start pkgs <- to define the list of packages and then run the following line to install all the packages.

install.packages(pkgs)

Also install the mmtable2 package, which needs to be installed separately as it is not currently available on CRAN:

devtools::install_github("ianmoran11/mmtable2")
  1. After all the packages have installed close all instances of R/RStudio before running your development version of R-Instat.

Note: Using multiple versions of R

If you need to use multiple versions of R, for example, when working on a branch or testing an older PR that still uses the the previous version of R, then you can force R-Instat to use a specific version of R.

In clsRLink.vb in the function StartREngine() edit the line REngine.SetEnvironmentVariables(), currently here to:

REngine.SetEnvironmentVariables("C:\Program Files\R\R-3.6.2\bin\i386", "C:\Program Files\R\R-3.6.2")

where the two paths are the location of the version of R you wish to use in R-Instat. R-Instat will then run with this version of R instead of your most recently installed version referred to the registry. Remember to change this line this back before committing any changes or making a pull request.

Adding a new R package to R-Instat

When to add a new R package

Adding a new R package requirement to R-Instat means users will have access to the functionalities of that package when they install R-Instat. However, it means increasing the size of the R-Instat installation, which can be significant depending on: the size of the package, the size of example data included, the number and size of dependencies of that package (which will also be included).

Generally an R package should be added when:

  • A dialog needs to use a function from the package
  • The package includes particularly interesting or useful example data sets which we would like users to have access to e.g. students or to be able to mention in an R-Instat tutorial document/video

In some rare cases we may wish to include an R package which satisfies neither of these but would be useful for users to have access to e.g. in the script window or in a half-way dialog where the package is not already explicitly mentioned. However, this should be done with caution and consider the benefits of adding this package for a potentially limited use case vs the increased installation size and dependencies created for all users. Note that users can also install their own R packages (with online access) from within R-Instat. Hence it may not be necessary to include the package as a dependency if the use case is small and the potential users will be able to install the R package themselves.

How to add a new R package

To include a new R package add the package name to the file instat\static\InstatObject\R\install_packages.R in the variable pkgs. This defines the direct packages required in R-Instat. You do not need to include the dependencies of this package. This will be done automatically. Do not change any other part of this file.

Include this change as part of your pull request where the change is needed e.g. adding or editing a dialog. If the package is being added just for its datasets or other use, make a pull request with this change.

A separate process is required to make R-Instat check that this package exists on start up. One of the lead developers will make this change after you have added the package.

By default, R-Instat does not load each package into the R environment on start up. This prevents potential conflicts and reduces start up time. Instead, package names are referred to explicitly e.g. dplyr::filter(). In the rare case that you also need your package to be loaded on start up, you can include this in the packs_to_load variable defined in instat\static\InstatObject\R\Rsetup.R. You also need to include a comment in this section to explain why the package is required to be loaded on start up.

Translations

By default, the R-Instat user interface displays English language text. The Options dialog allows the user to change to a different language. Currently, the user can select English, French or Portuguese. This section describes how to maintain or improve the current translations. It also describes how to add a new language (e.g. Russian).

The R-Instat translation system consists of three main areas:

The CrowdIn translation system

Please see Translating R-Instat for further details.

Text positioning

Translated text may be longer than the original English text. This means that text is overwritten by (or overwrites) other user interface elements. Therefore, the user interface needs to be tested with the translations, and any positioning issues need to be resolved. TODO

Translation mechanism

This is the mechanism, used by all languages, that facilitates the switching and display of the different translations. TODO