I'm curious to know if there is a way to save everything from the R console to a text file when an R script is submitted and executed "remotely" from Microsoft R client to Microsoft R server using the command remoteScript()
or remoteExecute()
.
For example, consider a simple R script 'test.R'
as follows:
set.seed(123)
x <- rnorm(100)
mean(x)
I know, to save all from the console, it can be executed in a Local R session as follows:
Local R session:
# Create a text file to save all from console
logfile <- file("C:/.../MyLog1.txt")
sink(logfile, append = TRUE)
sink(logfile, append = TRUE, type = "message")
# Execute in the local R session
source("C:/.../test.R", echo = TRUE, max.deparse.length = 1000000)
sink()
sink(type = "message")
The log file 'MyLog1.txt'
, as expected, has everything from the console:
> set.seed(123)
> x <- rnorm(100)
> mean(x)
[1] 0.09040591
Similarly, the same script can be executed with remoteScript()
after connecting to the R server.
Remote R session:
# Connect to the server and create a remote session
remoteLogin(...)
# Go back to the local R session
pause()
# Create a text file to save all from console
logfile <- file("C:/.../MyLog2.txt")
sink(logfile, append = TRUE)
sink(logfile, append = TRUE, type = "message")
# Execute in the remote R session
remoteScript("C:/.../test.R")
sink()
sink(type = "message")
But the log file 'MyLog2.txt'
looks different, as shown below:
[1] 0.09040591
$success
[1] TRUE
$errorMessage
[1] ""
$outputParameters
list()
$consoleOutput
[1] "[1] 0.09040591\r\n"
$changedFiles
list()
$backgroundUpdate
[1] 0
It has only the "Output" and some additional information. Each line of the code with '>'
command prompt was not printed like 'MyLog1.txt'
. It may be because there is no option like echo=TRUE
for remoteScript()
.
Can anybody help me out with any alternative?
Thanks..