Here's a template for the the batch scripts we use to setup R environments and run data processing R scripts....automatically!
The following instructions can be copied and pasted into your repository's readme file as markdown code. Open a pull request or issue on github to suggest changes to the batch script or the documentation.
Batch scripts allow for the automation of a variety of windows tasks such as installing and running programs and creating new folders. We have developed batch scripts that
- Automatically install all the software you need to run our data refresh scripts and
- Automatically run the refresh pipelines
Here's how to use them!
$\text{\color{green}Automatically set up and run the project using batch scripts}$
Batch files instructions
Prerequisite steps
Step 1: Create a GitHub account
Creating a personal account should be pretty easy. If you need to connect to your organization's github page, you'll have to contact your organazation's admin to get a user licence and join the correct github groups.🙂
Step 2: Create a GitHub personal access token (PAT)
A personal access token acts as a password to your Github account and allows you to clone a copy of repositories onto your personal computer, pull in changes someone else made from github, and push any changes you made to github.
Instructions for creating a personal access token are available here.
Do the following when creating a token:
- Choose the
$\text{\color{purple}classic token}$ option - Set the expiration date to
$\text{\color{purple}90 Days}$ - Select
$\text{\color{purple}all the scopes}$
After you've created the PAT,
Step 3: Run the .bat
file
.bat
filedownload the batch file that you want to run. Here's an example batch script.
If you are using edge as your web browser, you may see a warning when you download the file. Expand the
$\text{\color{purple}Downloading batch files on Edge}$
When you download the file on Edge, you may see a warning in your downloads that looks like this:

Hover over the file to see three dots ...
click on the three dots and choose the keep
option
After this message appears, expand the Show more
arrow
Then click on the Keep anyway
option
The file should now download!
After the file downloads, find the file in your downloads folder and and then double click on it to run the script:
When this window pops up, click on more info
Then click run anyway
While the software is running
After the script starts running, there are a few things that may require your input. Here's how to deal with them! Depending on your current setup, you may not see all of these things.
Install R
If R is not currently installed on your computer, the script will attempt to install version 4.4.0 from the company portal. If this doesn't work you may need to install R manually. Depending on your organization's install policies you may be able to modify this script to use winget to install R. (Although currently winget only has up to version 4.2.2, and I wouldn't recommend that version because it doesn't have the patch for a security vulnerability that was fixed in R version 4.4.0). After R is installed, re-run the batch script.
Enter your password when installers launch
This script checks your computer for git and Rtools and installs them if they're missing. If an installer window launches, enter your password. The installer needs admin rights to work properly and needs your password to enter admin mode.
Re-run the script after git installs
If the script installs git on your machine for the first time you will need to close the command prompt window and double click on the batch script file again to complete the installation. If the script stops running and you see this message, close the command prompt window and re-run the script.
Rtools error?... Ignore and continue
The script will automatically install Rtools. If during installation, you see this error, just click Ignore this error and continue
:
You do not need to close and re-run the script after Rtools is done installing like you do for git
Use your PAT when asked to login to github
If you have not previously connected git on your computer to your github account you will be prompted to login to github. That window looks like this:
Click on the token
column on the right and then enter the personal access token that you created in step 2 in the box and click Sign in
Choose a project folder
By default the script will download all the files you need from GitHub to a folder on your computer called C:/users/[YOUR USERNAME]/R_projects
. If the folder doesn't already exist the script will create it. You also have the option to change the default location. To change choose option 2 when you see this screen:
Choose 1 to launch a window that lets you choose a new folder.
Choose 2 to continue running the script using the default location.
If you choose to use a new folder, the following window will pop up:
Choose a new folder then click ok. If you click cancel the script will exit silently and you will need to rerun the batch script. The Make New Folder
option hasn't been extensively tested, so if you'd like to create a new folder, it's recomended that you first exit the script, manually create the new folder, then rerun the batch script and choose the new folder you created.
Refresh data?
After all the required software is downloaded and configured, you will see the following prompt asking you if you'd like to refresh the data
Choose 1 to exit the script and view the project folder
Choose 2 to refresh the data
If you choose option 2, the batch script will automatically run the R scripts contained in the repository to refresh the data. You specify the r script to run in the batch script on line 704.
Subsequent refreshes
Rerun the batch script in the project folder
The first time you run the script it will create a project folder. Inside the project folder there will be a copy of the batch script. To refresh the data, just navigate to the project folder and double click on the batch script.
You should use the version of the script stored in the project folder not the version you downloaded from GitHub or Teams the first time.
Suggestions?
Pull requests are welcome!