Re: is there a way to change fit to csv
Hi,
In case one wishes to read a NONMEM table containing multiple table headers (e.g. as created using $SIMULATION with more than one subproblem) then you need to remove the unwanted table headers e.g.
read.nm<-function(fileName) {
dat=read.csv(fileName,sep="",header=T,skip=1,stringsAsFactors=F)
#remove TABLE and data item header from subsequent sub-problems
temp <- dat[dat[,1]!="TABLE"&dat[,1]!=names(dat[1]),]
temp <- as.data.frame(apply(temp,2,as.numeric))
return(temp)
}
d<-read.nm("table.tbl")
> Chandramouli,
>
> Justin's solution is elegant and works on most datasets produced. However, occasionally NONMEM outputs "numbers" formatted like the following 1.00-103 which should be 1.00E+103. I have created a small function that reads in NONMEM datasets and fixes this problem:
>
> read.nm<-function(file,na.strings=c("NA","."),...){
>
> nmf<-readLines(file,n=-1)[-1]
>
> nmf<-gsub("+",",",nmf)
>
> nmf<-gsub("^,","",nmf)
>
> nmf<-gsub("([0-9])([-+])([0-9])","\\1E\\2\\3",nmf)
>
> tf<-tempfile()
>
> cat(nmf,file=tf,sep="\n")
>
> d<-read.csv(tf,na.strings=na.strings,...)
>
> unlink(tf)
>
> return(d)
>
> }
>
> Once this function is sourced, all you need to do is read NONMEM in through the new function:
>
> d<- read.nm("table.tbl")
>
> Matt.
>
> *From:* [email protected] [ mailto: [email protected] ] *On Behalf Of *Justin Wilkins
>
> *Sent:* Tuesday, September 14, 2010 1:24 AM
> *To:* Chandramouli Radhakrishnan
> *Cc:* [email protected]
> *Subject:* Re: [NMusers] is there a way to change fit to csv
>
> Dear Chandramouli
>
> Typically something like
>
> > fit <- read.table("run1.fit", head=T, skip=1)
>
> (where run1.fit is a typical NONMEM table file, with headers) should do what you need. If not, have a look at the NONMEM table in a text editor - NONMEM tables are basically space-delimited text files, which R's read.table function ought to be able to handle easily.
>
> Best
> Justin
>
Quoted reply history
> On 14 September 2010 07:42, Chandramouli Radhakrishnan < [email protected] < mailto: [email protected] >> wrote:
>
> Hi
>
> I am trying to use R to produce plots from NONMEM fit file. However, I could not get R to read the fit file
>
> Can any one help?
>
> Kind Regards
>
> *Chandramouli Radhakrishnan*
>
> * *
>
> --
> Justin Wilkins
> -----------------------------
> Colmarerstrasse 31
> 4055 Basel
> Switzerland
> -----------------------------
> Email: [email protected] <mailto:[email protected]>
> Skype: kestrel_za2002
> Mobile: +41 76 561 0949
>
> ------------------------------------------------------------------------
>
> This e-mail (including any attachments) is confidential and may be legally privileged. If you are not an intended recipient or an authorized representative of an intended recipient, you are prohibited from using, copying or distributing the information in this e-mail or its attachments. If you have received this e-mail in error, please notify the sender immediately by return e-mail and delete all copies of this message and any attachments.
>
> Thank you.
--
Nick Holford, Professor Clinical Pharmacology
Dept Pharmacology& Clinical Pharmacology
University of Auckland,85 Park Rd,Private Bag 92019,Auckland,New Zealand
tel:+64(9)923-6730 fax:+64(9)373-7090 mobile:+64(21)46 23 53
email: [email protected]
http://www.fmhs.auckland.ac.nz/sms/pharmacology/holford