Alex M Alex M - 3 months ago 7
R Question

R executable not working, but script works fine

I have created a script that works fine when I run it from Rstudio.

However, when I save it as "Rexec" and try to run it by double clicking, it only partially launches.

I get a navigate gui pop-up to the initial file location, but then nothing happens after that. The black box with various messages displays some quickfire messages and closes before i can see what happened.

I have run another, much bigger script this way and had no problems.

This script is distinct in that when I run it through RStudio, there are multiple interactive gui dialog pop-ups that require some input from me i.e. choose column headers with

or save file as png via using:

png.filename <- tclvalue(tkgetSaveFile(initialfile = "choose name.png",
filetypes = "{ {PNG Files} {.png} }"))

How can I check what is causing the problem i.e. output an error log?


I found this example of how to get error log: Output error/warning log (txt file) when running R script under command line.

I just added these lines to my code as follows:

zz <- file("error_log.text", open="wt")
sink(zz, type="message")

....code chunk....


This writes a text file to the directory containing "foo_script.Rexec" with some messages that contain the following:

Error in select.list(names(MQ.file.DF), multiple = TRUE, title = "Choose variables to remove",  : 
  select.list() cannot be used non-interactively
Execution halted

select.list() seems to be the issue, hence the process crashing.

Work around - I changed to using tk_select.list and that seems to sort the problem. Script runs without a crash. I kind of prefer select.list as it supports click and dragging of cursor to highlight multiple columns, whereas with tk_select.list you have to click one at a time. I'll take a few more clicks as long as it runs ok. I hope this helps someone with a similar issue.