Hello all:
I have determined the reason for nmfe74.bat and nmfe73.bat behaving differently 
in handling standard output when executed from R (it turns out I solved this 
for Chuanpu Hu a few months ago).

The difficulty occurs only in Windows, using gfortran compiled NONMEM, executed 
from a system call from within R.

The output re-direction and/or console output to gfortran programs is 
mis-managed in R’s system call.  This occurs in both nmfe73.bat and nmfe74.bat. 
 But in nmfe74.bat there is an additional redirection command, which is fatal 
when not properly done in R, whereas in nm73.bat, the sole re-direction command 
not properly done merely results in the contents of FMSG not transferring to 
the main NONMEM result file.

Users may call
Sys.unsetenv("GFORTRAN_STDOUT_UNIT")
at the beginning of an R session, as recommended by Tarj Sohata, or you can use 
a modified nmfe74.bat file located at:
https://nonmem.iconplc.com/nonmem741/extra/run


Robert J. Bauer, Ph.D.
Senior Director
Pharmacometrics R&D
ICON Early Phase
820 W. Diamond Avenue
Suite 100
Gaithersburg, MD 20878
Office: (215) 616-6428
Mobile: (925) 286-0769
robert.ba...@iconplc.com<mailto:robert.ba...@iconplc.com>
www.iconplc.com<http://www.iconplc.com/>



From: owner-nmus...@globomaxnm.com<mailto:owner-nmus...@globomaxnm.com> 
[mailto:owner-nmus...@globomaxnm.com] On Behalf Of Smith, Mike K
Sent: Tuesday, January 02, 2018 2:52 AM
To: HUI, Ka Ho; Tarj Sahota; Devin Pastoor
Cc: Bill Denney; nmusers@globomaxnm.com<mailto:nmusers@globomaxnm.com>
Subject: RE: [NMusers] Failure to execute NONMEM from R

Likewise, glad to report that Sys.unsetenv("GFORTRAN_STDOUT_UNIT") works. You 
need to submit this command (preferably at the top of an R script) each time 
you start R. The question remains *WHY*??? And what is different between 
NONMEM-7.3 and NONMEM-7.4 (to Devin's point).

I've managed to get NONMEM-7.4 to run using system, system2 and shell.
system2(command = 'c:/nm74g64/run/nmfe74.bat',
args = c('run1.mod',
'run1.lst'),
stdout = TRUE, stderr = TRUE,wait = TRUE)

cmd <- paste("c:/nm74g64/run/nmfe74.bat run1.mod run1.lst")
system( command = cmd)

or using PsN Execute:
system2(command = 'c:/strawberry/perl/bin/execute-4.7.9.bat',
args = c('run1.mod', '-nm_version="nonmem-7.4"'),
stdout = TRUE, stderr = TRUE,wait = TRUE)

-----Original Message-----
From: owner-nmus...@globomaxnm.com<mailto:owner-nmus...@globomaxnm.com> 
[mailto:owner-nmus...@globomaxnm.com] On Behalf Of HUI, Ka Ho
Sent: 22 December 2017 02:27
To: Tarj Sahota; Devin Pastoor
Cc: Bill Denney; nmusers@globomaxnm.com<mailto:nmusers@globomaxnm.com>
Subject: [EXTERNAL] RE: [NMusers] Failure to execute NONMEM from R

Thanks Tarj for your advice and it works!

sys.unsetenv("GFORTRAN_STDOUT_UNIT") is the line that is needed.

Matthew

-----Original Message-----
From: Tarj Sahota [mailto:t.saho...@gmail.com]
Sent: Thursday, December 21, 2017 10:18 PM
To: Devin Pastoor <devin.past...@gmail.com<mailto:devin.past...@gmail.com>>
Cc: HUI, Ka Ho 
<matthew....@link.cuhk.edu.hk<mailto:matthew....@link.cuhk.edu.hk>>; Bill 
Denney <b...@denney.ws<mailto:b...@denney.ws>>; 
nmusers@globomaxnm.com<mailto:nmusers@globomaxnm.com>
Subject: Re: [NMusers] Failure to execute NONMEM from R

I get the same errors as Matthew (with NM 7.4.1+gfortran on windows) - I forgot 
to mention that in order to get it working on my machine I also need to use 
shell() rather than system()/system2()/... along with 
Sys.unsetenv("GFORTRAN_STDOUT_UNIT"). Not sure if that helps you, but it fixes 
the issue with my windows machine.

Tarj.

On Thu, Dec 21, 2017 at 11:49 AM, Devin Pastoor 
<devin.past...@gmail.com<mailto:devin.past...@gmail.com>> wrote:
> I believe the problem is actually that is cross referenced
> http://discuss.go-isop.org/t/psn-execute-failed-to-start-when-called-f<http://discuss.go-isop.org/t/psn-execute-failed-to-start-when-called-f>
> rom-rstudio/1119
> It is not a path issue
>
> Mike and I have had a small amount of offline exploration and can
> confirm it a pervasive issue with NM74 being called from Rstudio. This
> is not just PsN, I also use a separate language (go) to manage the
> nmfe commands and invoking that from Rstudio via system2/processx/sys
> all fails in the same fashion. At this point, I believe it is likely a
> permissions issue, but I am unsure of if the (primary) culprit is nonmem or 
> Rstudio.
>
> We will need to get Bob's input whether there was a change in the
> mechanics of how nonmem is invoked from 73 --> 74 to hopefully narrow
> the surface area of what could be causing the problem.
>
> On Wed, Dec 20, 2017 at 10:47 PM HUI, Ka Ho
> <matthew....@link.cuhk.edu.hk<mailto:matthew....@link.cuhk.edu.hk>>
> wrote:
>>
>> Thanks for attending the problem, Bill.
>>
>>
>>
>> Exactly which path should I be looking for? Am I to check if the
>> desired path exists in the list or not?
>>
>> I tried adding the paths for NONMEM, PsN, R and Rstudio into the list
>> and executed commands in R again – nothing has changed so far. Any idea?
>>
>>
>>
>> Thanks,
>>
>> Matthew
>>
>>
>>
>> From: Bill Denney [mailto:b...@denney.ws]
>> Sent: Thursday, December 21, 2017 11:11 AM
>> To: HUI, Ka Ho 
>> <matthew....@link.cuhk.edu.hk<mailto:matthew....@link.cuhk.edu.hk>>
>> Cc: nmusers@globomaxnm.com<mailto:nmusers@globomaxnm.com>
>> Subject: Re: [NMusers] Failure to execute NONMEM from R
>>
>>
>>
>> Hi Matthew,
>>
>>
>>
>> Since everything is working when run directly from the command line
>> (cmd), I would guess that it's something like a path issue.
>>
>>
>>
>> Check your path at the command prompt (type "path") and in RStudio
>> ("Sys.getenv("PATH")").
>>
>>
>>
>> Thanks,
>>
>>
>>
>> Bill
>>
>>
>> On Dec 20, 2017, at 21:54, HUI, Ka Ho 
>> <matthew....@link.cuhk.edu.hk<mailto:matthew....@link.cuhk.edu.hk>>
>> wrote:
>>
>> Dear NMusers,
>>
>>
>>
>> Recently I need to execute NONMEM 7.4 from Rstudio terminal. I have
>> tried the following scripts:
>>
>> `system2(“execute FIT_01.mod”)` #Through PsN,
>> using `system2`
>> `shell(“execute FIT_01.mod”)` #Through
>> PsN, using `shell`
>> `write(“execute FIT_01.mod”, “FIT_01.bat”)` `shell(“FIT_01.bat”)`
>> #Through PsN, using `shell` to call a batch file `write(“execute
>> FIT_01.mod”, “FIT_01.bat”)` `shell.exec(“FIT_01.bat”)` #Through PsN,
>> using `shell.exec` to call a batch file The above commands, but call
>> through C:/nm74g64/run/nmfe74.bat directly
>>
>>
>>
>> The above were also tested using the test dataset `CONTROL5`
>>
>>
>>
>> Results:
>>
>> gave me the `running command '"execute FIT_01.mod"' had status 127`
>> warning without any execution
>>
>>
>>
>> (2)-(4) gave me the following messages:
>>
>> 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
>>
>> (5) similar to (1) but the status/error code became 107
>>
>>
>>
>> None of the above has led to a successful NONMEM run. But the above
>> command lines work when outside R (i.e. through `cmd` +/- PsN)
>>
>> Is there anyone experiencing the same issue?
>>
>>
>>
>> System/software info:
>>
>> OS: Windows 10
>>
>> NONMEM v7.4
>>
>> R3.4.2
>>
>> Rstudio v1.1.383
>>
>>
>>
>> Best regards,
>>
>> Matthew Hui
>>
>> PhD Student
>>
>> School of Pharmacy
>>
>> Faculty of Medicine
>>
>> The Chinese University of Hong Kong
>>
>>
<br /><br />
ICON plc made the following annotations.
------------------------------------------------------------------------------
This e-mail transmission may contain confidential or legally privileged 
information that is intended only for the individual or entity named in the 
e-mail address. If you
are not the intended recipient, you are hereby notified that any disclosure, 
copying, distribution, or reliance upon the contents of this e-mail is strictly 
prohibited. If
you have received this e-mail transmission in error, please reply to the 
sender, so that ICON plc can arrange for proper delivery, and then please 
delete the message.

Thank You,

ICON plc
South County Business Park
Leopardstown
Dublin 18
Ireland
Registered number: 145835

Reply via email to