ISoP ISoP on Twitter | ACoP ACoP on Twitter | PAGE | WCoP | PAGANZ | PAGJa

PsN 'execute' failed to start when called from Rstudio


Dear all,

This is my first time posting here =]

I have been constructing study datasets and control streams from Rstudio. Now I wish to call PsN ‘execute’ from Rstudio so that I can run things (Rscript and NONMEM) all together using in Rstudio, which would allow me to analyze my result right away using R.

I tried the following script in Rstudio (I have already set the wd to the folder containing FIT_01.mod):

system2("execute FIT_01.mod")

shell("execute FIT_01.mod")

write("execute FIT_01.mod", "FIT_01.bat")

write("execute FIT_01.mod", "FIT_01.bat")

(1) gave me the running command '"execute FIT_01.mod"' had status 127 warning and did not execute anything. (2), (3) and (4) gave me the following messages either in R console or a separate shell:
Starting 1 NONMEM executions. 1 in parallel.
S:1 ..
All executions started.
Starting NMTRAN
NMtran failed. There is no output for model 1. Contents of FMSG:

Not restarting this model.
F:1 ..
execute done

However, my control worked perfectly well if I manually execute the control stream through cmd or the above batch file created in (3) or (4). It just doesn’t work when I try to execute it from Rstudio.

Does anyone have any idea what is the problem behind?

Some info about my system:
OS: Windows 10
Rstudio v1.1.383


I’m seeing exactly the same issue.

When trying to run NONMEM-7.4 from R running on Windows 10 trying to call c:/nm74g64/run/nmfe74.bat, I can’t get the model to run. R is creating valid system commands which run outside of R, but running from an R script, or from the RStudio terminal, or via PsN (using execute like you) doesn’t work.

Apparently this issue is not seen with other operating systems.
Using the same commands e.g. calling c:/nm730/run/nmfe73.bat directly or using rspeaksnonmem with NONMEM-7.3 from R / RStudio works fine.

@dpastoor has confirmed this issue as well.

I think we need some assistance from Bob Bauer (and perhaps RStudio) to help figure out what’s going on.


Thank you for attending the question!

Should I post it onto the nmusers network?


Yes. I can encourage others to post their findings.

It’s important to note that this isn’t just a problem of calling NONMEM via PsN / execute from R, but rather specifically about calling out to nmfe74.bat from within R. You can verify quite quickly by going to the RStudio terminal and typing C:/nm74g64/run/nmfe74.bat mymodel.modl mymodel.lst with some reasonable model file.

From what I can see there are a few differences in the .bat file between nmfe73.bat and nmfe74.bat. I should post the comparison for reference.


And just to be very clear, PsN will run NONMEM-7.4 just fine outside of R. This problem seems very specific to calling NONMEM from inside R via system, system2 and shell (I’ve tried all 3!).

Also, this problem does NOT seem to appear when calling NONMEM-7.4 from R on Mac or Linux.


Though not fully aware of the rationale behind. Tarj’s advice on NMusers network works for me.

I just need to precede the shell() command with sys.unsetenv("GFORTRAN_STDOUT_UNIT"). Then NONMEM run is executed!