The Flexibility of Remote and Local R Workspaces

[This article was first published on Revolutions, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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.

mrsdeploy comes bundled with installations of Microsoft R Client and Microsoft R Server.

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 session and commandline:

Argument Description
session If TRUE, create a remote session.
commandline If 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:

Argument Description
pause When executed from the remote R session, returns the user to the local > command prompt.
resume When executed from the local R session, returns the user to the REMOTE> command prompt, and sets a remote execution context.
putLocalObject 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.

Feedback

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!

To leave a comment for the author, please follow the link and comment on their blog: Revolutions.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)