deployrInput: Declare inputs to ensure R script input portability.

View source: R/deployrInput.R

deployrInputR Documentation

Declare inputs to ensure R script input portability.

Description

The deployrInput function allows you to declare the required inputs for your R script and provide default values for these inputs. Default values ensure that your script can run successfully and that your R code is portable across your local environment and in the DeployR server environment.

The inputs can be used to:

  • Test a script locally within your R IDE environment AND again remotely within the DeployR Repository Manager Test page. In both test cases, use the default values to verify consistent behavior across environments.

  • Provide client application developers with clear guidance as to which script inputs their application will be required to supply to produce meaningful output.

For more information on declaring your inputs, see the ‘Writing Portable R Code’ document for your DeployR version on the official DeployR website (http://go.microsoft.com/fwlink/?LinkId=708337).

Usage

deployrInput(content)

Arguments

content

A valid JSON string configuration using the following structure:

name

Required. A character string specifying a valid R object name.

default

Required. A default value for the input if one isn't passed by the calling application. If render is character, then the default value must be a character string. If render is factor or ordered, then the value can be a character string or a numeric value as long as the value matches either one of the levels or one of the labels.

render

Required. A character string specifying the type of input expected. Possible values are the classes integer, numeric, logical, character, factor, ordered, vector, matrix, list, and data.frame.

label

A character string specifying the label that can be displayed in the calling application's interface.

min

If the render value is numeric or integer, then the minimum value accepted.

max

If the render value is numeric or integer, then the maximum value accepted.

levels

If the render is character, factor, or ordered, then an optional vector of possible values. If the render is factor, or ordered, can be a character string or a numeric value but must match default. For character strings, enclose each level in quotes.

labels

If the render value is character, factor, or ordered, then either an optional vector of label strings for the levels in the same order as levels.

...

Additional arguments.

Details

The name, render, and default arguments are required. The entire input to the deployrInput function must be a valid JSON string. Within that string, JSON dictates that the argument names be double-quoted as should any strings.
Examples:

  • deployrInput('{"name": "myName", "render": "integer", "default": 5}')

  • deployrInput("{\"name\": \"myName\", \"render\": \"integer\", \"default\": 5}")

  • deployrInput('{"name": "myName", "render": "logical", "default": "true"}')

Important! In order to display an input configuration in the Test page of the DeployR Repository Manager, the argument for the deployrInput function must be a single literal string, and cannot be another function or variable. For example, the following code could be used in an R script; however, no controls would appear in the Script Inputs pane in the Test page.

args <- '{"name": "myName", "render": "integer", "default": 5}'
deployrInput(args)

Examples

## Not run: 
 # Creates an integer variable named age if it does not exist
 deployrInput('{ "name": "age", "label": "Age", "render": "integer", "default": 6 } ')        
 
 # Creates a number variable named amt if it does not exist
 deployrInput('{ "name": "amt", "label": "Amount", "render": "numeric", 
    "default": 6, "min": 5, "max": 10 } ')          
 
 # Creates a number variable named amt if it does not exist
 deployrInput('{ "name": "amt", "label": "Amount", "render": "numeric", "default": 6 } ')
                 
 # Creates a logical variable named ownHome if it does not exist
 deployrInput('{ "name": "ownHome", "label": "Homeowner", "render": "logical", 
    "default": "TRUE" } ')
                 
 # Creates a character variable named fname if it does not exist
 deployrInput('{ "name": "fname", "label": "First Name", "render": "character", 
    "default": "Sue" } ')
                  
 # Creates a character variable named filetype if it does not exist
 deployrInput( '{ "name": "filetype", "label": "File Type", "render": "character", 
    "default": "png", "labels": [ "png", "bmp", "jpg", "tiff" ] } ')
                  
 # Creates a factor variable named filetype if it does not exist
 deployrInput( '{ "name": "filetype", "label": "File Type", "render": "factor", 
    "default": "png" } ')
                  
 # Creates an ordered factor variable named rating if it does not exist
 deployrInput('{ "name": "rating", "label": "Rating", "render": "ordered", 
    "levels": [ "Good", "Better", "Best" ], "default": "Good" } ')

## End(Not run)


deployr/deployrUtils documentation built on July 5, 2023, 9:58 a.m.