forked from fishfollower/hideR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.R
50 lines (47 loc) · 1.21 KB
/
script.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
library(TMB)
get.stuff <- function(filen){
lin <- readLines(filen)
idxNam <- grep("^[[:alpha:]]", lin)
doone <- function(i){
idxNam <- c(idxNam,length(lin)+1)
x <- read.table(textConnection(lin[(idxNam[i]+1):(idxNam[i+1]-1)]))
names(x) <- NULL
if((nrow(x)==1) | (ncol(x)==1)){
x <- as.numeric(x)
}else{
x <- as.matrix(x)
}
x
}
ret <- lapply(1:length(idxNam), doone)
nam <- lin[idxNam]
nam <- sub('RANDOM', '', nam)
nam <- sub('[[:space:]]+', '', nam)
names(ret) <- nam
ret
}
get.random <- function(filen){
lin <- readLines(filen)
idxNam <- grep("^[[:alpha:]]", lin)
nam <- lin[idxNam]
nam<-nam[grep("RANDOM", nam)]
nam <- sub('RANDOM', '', nam)
nam <- sub('[[:space:]]+', '', nam)
if(length(nam)==0){
nam <- NULL
}
nam
}
runit <- function(name){
compile(paste(name,".cpp", sep=""))
dyn.load(dynlib(name))
data <- get.stuff(paste(name, ".dat", sep=""))
param <- get.stuff(paste(name, ".pin", sep=""))
ran <- get.random(paste(name, ".pin", sep=""))
obj <- MakeADFun(data, param, random=ran, DLL=name)
opt <- nlminb(obj$par, obj$fn, obj$gr)
rep<-sdreport(obj)
sink(file=paste(name, ".std", sep=""))
print(summary(rep))
sink()
}