Skip to content

1๏ธโƒฃ Analysis with R โ€‹

You can use R to perform analysis with Aplos NCA using API calls via secure http requests. Aplos has published an R package on CRAN aplosNCA that includes all of the functions you need to run analyses. Issues can be reported on the github repository. If you use your email and a password to access Aplos NCA we recommend that you save your authentication information in a hidden file on your computer rather than including it in your R scripts. If you use single sign on (SSO), we recommend that you save a current JWT in a hidden file rather than putting it in your R scripts.

DescriptionFileLink to file
Security filesecurity.txt๐Ÿ“„
JWT filejwt.txt๐Ÿ“„

Functions โ€‹

A complete list of functions can be found with the R package. A brief description of each can be found below:

FunctionDescription
aplos_get_jwtRequest authentication JSON Web Token (jwt) from Amazon Cognito. This token is required for all API calls. This uses your username and password. If you are using SSO, you will not use this function to get a jwt.
aplos_get_upload_urlRequest Aplos NCA for secure URL to upload input data file.
aplos_upload_fileUpload file to Aplos NCA
aplos_execute_analysisInitiate analysis workflow
aplos_execution_statusRequest status of previously initiated analysis workflow (including completed analyses)
aplos_download_resultsGet secure URL to download results of previously completed analysis
aplos_fetch_resultsDownload results from previously completed analysis

Security file for login โ€‹

Security information should never be stored within a script that is shared with other users. One method to simplify use of security information within R is to create a text file with the security information that is then imported into the script and used. Let others know that they will need to use their own security information file when using the code. The security.txt file ๐Ÿ“„ shows the format, but contains no information.

The information for everything except the username and password can be obtained from the Aplos NCA Web Interface under the [Profile | API Configuration]. API Configuration

Enter the information from your account inside the quotation marks and then save the file on your computer to be imported into the R script.

r
# Example of what is in security file
COGNITO_CLIENT_ID="<value here>"
COGNITO_USER_NAME="<value here>"
COGNITO_PASSWORD="<value here>"
COGNITO_REGION="<value here>"
APLOS_API_URL="<value here>"

# Example code to read security file and assign values to variables
source(".env")
username = COGNITO_USER_NAME
password = COGNITO_PASSWORD
client_id = COGNITO_CLIENT_ID
region = COGNITO_REGION
api_url = APLOS_API_URL

JWT for login โ€‹

Users that login with SSO cannot generate a JSON web token by requesting it with a username and password. Users should instead copy the current token from the web browser by following the instructions below.

That text should be saved in a file and then imported into the script and used directly as the authentication token. Note that JWTs are only valid for 1 hour. Because every request requires authentication, you may need to refresh your token from the web browser if you spend more than an hour working on your R code.

Enter the information from your account inside the quotation marks and then save the file on your computer to be imported into your R script.

r
# Example of what is in jwt file
JWT="<value here>"
APLOS_API_URL="<value here>"

# Example code to read security file and assign values to variables
source("jwt.txt")
token = JWT
api_url = APLOS_API_URL