The spserver.* functions

When the TERR or open-source R engine is executing on the server, it defines a set of functions that the code can call to access information about the current execution environment.

Functions on the server for accessing information about the execution environment
Function Name Description
spserver.file(file=””, user.name=spserver.user.name())
Returns the local file path for permanent storage for the given user.
  • If user.name is not given, the default is to use the current user name.
  • If user.name is given as "", this specifies the common storage area.

The file argument is pasted on the end to construct a complete URL.

spserver.home
Returns the server’s home path.
spserver.on.server() 
A Spotfire Statistics Services job.

The expression (exists("spserver.on.server") && spserver.on.server()) can be used in code that is executed either on the server or the desktop.

Note: just calling spserver.on.server() by itself fails on the desktop.

This function is useful if you are calling a function that requires different behavior between a desktop environment and a server environment. For example, if you are calling a function that generates a graph on the server, you might want the graph to be written to a file. When you call such code on the desktop, you might want to create a window displaying the graph. For example:

if (exists("spserver.on.server") && spserver.on.server()) {
     # if running on server: write the
     # graph to a file
     myfile<-spserver.results.file("xx.ps")
     postscript(myfile)
     draw.my.graph()
     dev.off()
     spserver.results.url("xx.ps")
} else {
     # if not running on server, use the default graphics device:
     draw.my.graph()
}
spserver.results.url(file="")
Return the WebDAV URL that can be used for accessing the result files for this execution. The file argument is pasted on the end, to construct a complete URL. Illegal URL characters (like spaces) are converted to the appropriate URL characters.
spserver.results.file(file="")
Returns a file name in the local working directory for storing results for this execution. If file is "", this returns the results directory, otherwise the file argument is added to the directory to construct a complete file path.
spserver.service.id
Returns the server’s ID.
spserver.service.url
Returns the server’s URL.
spserver.share
Returns the server’s share.
spserver.url(file="", user.name=spserver.user.name())
Return the URL for a WebDAV directory providing permanent storage for the given user. If user.name is not given, the default is to use the current user name. If user.name is given as "", this specifies the common storage area. The file argument is pasted on the end, to construct a complete URL. Illegal URL characters (like spaces) are converted to the appropriate URL characters.
spserver.url.to.file(url=””)
Returns the local file path corresponding to the provided URL in the server WebDAV root.

If the URL is not local to the server's WebDAV root, this function returns null.

spserver.user.name()
Returns the user name specified when the current job was created.

This might return the empty string, if the server does not require user names to be given.

spserver.user.password()
Returns the password specified when the current job was created.

This might return the empty string, if the server does not require user names and passwords.

spserver.webdav.root()
Returns the local file path corresponding to the WebDAV root.
spserver.webdav.url()
Return the URL for a WebDAV directory providing permanent storage for the given user. If user.name is not given, the default is to use the current user name. If user.name is given as "", this specifies the common storage area. The file argument is pasted on the end, to construct a complete URL. Illegal URL characters (like spaces) are converted to the appropriate URL characters.

Example

The most useful of these functions are spserver.results.url and spserver.results.file, which give simple access to the transient file names. For example, you could evaluate an expression:

  {
     myfile<-spserver.results.file("xx.ps")
     postscript(myfile)
     draw.my.graph()
     dev.off()
     spserver.results.url("xx.ps")
}

This job result would be the complete URL for accessing the resulting file.