by Sean Wells, Senior Software Engineer, Microsoft
The mrsdeploy R package facilitates Remote Execution and Web Service interactions from your local R IDE command line against a remote Microsoft R Server instance. Both core features can be used independently of one another or combined to support different convenient workflows. These different workflows composed together can produce some creative R development and operationalization solutions.
Before using any
mrsdeploy API you must first authenticate against the R Server and before we authenticate we should become familiar with the different authentication approaches and their supported arguments. Currently, there are two ways to authenticate:
remoteLogin()using an on premises Active Directory server on your network:
remoteLogin( endpoint, session = TRUE, diff = TRUE, commandline = TRUE, username = NULL, password = NULL )
remoteLoginAAD()using Azure Active Directory in the cloud:
remoteLoginAAD( endpoint, authuri = NULL, tenantid = NULL, clientid = NULL, resource = NULL, session = TRUE, diff = TRUE, commandline = TRUE )
Both APIs are equivalent in that they provide the means to authenticate against a Microsoft R Server instance. Take special note of the arguments
TRUE, create a remote session.
TRUE, creates a REMOTE command line in the R console. REMOTE command line is used to interact with the remote R session. Parameter is only valid if session parameter is TRUE.
These two parameters are subtle yet can produce bold context switches from your local R workspace. Depending on their values, you can end up in one of three post authentication command line states in the R console:
State 1 – Remote Command Line
Authenticate, create a remote R session, and transition to the remote REPL command line. The default prompt
REMOTE> indicates you are now interacting with your remote R session and are no longer in your local R environment:
# Taking the default arguments (session = TRUE, commandline = TRUE) > remoteLogin("http://localhost:12800") REMOTE>
State 2 – Local Command Line
Authenticate, create a remote R session, and remain in your local R environment:
> remoteLogin("http://localhost:12800", session = TRUE, commandline = FALSE) >
State 3 – Local Command Line No remote session
Authenticate, do not create a remote R session, and remain in your local R environment:
> remoteLogin("http://localhost:12800", session = FALSE) >
Now that we understand the different authentication scenarios and their arguments we can begin to compose them together with other supported functions. The
mrsdeploy package provides many convenience functions to aid workflow from the R IDE command line. Listed below are a few that deal with context switching between your local and remote sessions post authentication:
|When executed from the remote R session, returns the user to the local
> command prompt.
|When executed from the local R session, returns the user to the
REMOTE> command prompt, and sets a remote execution context.
|Puts an object from the workspace of the local R session and loads it into the workspace of the remote R session.
See the documentation for a full list of supported functions.
Expanding on State 1 as shown above, here we define an interactive authentication workflow that spans both our local and remote environments.
The same outcome can be achieved with State 2’s authentication workflow as it differs only in the R environment order. Here we start out in the local R session then move to the remote R session.
Finally, State 3’s workflow demonstrates authentication without a remote R session being created
session = FALSE. This is useful if the intention is to only work with the Web Service functionality of the
mrsdeploy package. Here we authenticate and remain confined within our local R session in order to publish and consume a service.
Note Web Service management can only occur locally. Attempting to use the service APIs during remote interaction
REMOTE> will result in a error.
I am interested in seeing what people build. If you have any feedback on the above approach or the
mrsdeploy package in general, please leave a comment below.
Happy New Year!