Skip to content

Commit

Permalink
remove is.R
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenkewu committed Jan 29, 2024
1 parent 5ac0b75 commit a20f4bd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 28 deletions.
3 changes: 3 additions & 0 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Version: 1.0.3
Date: 2024-01-29 20:37:03 UTC
SHA: 5ac0b750ae2212936776f280399c2c8e84f04d4d
40 changes: 20 additions & 20 deletions R/adhoc-imports.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ jags.sims <- function (parameters.to.save, n.chains, n.iter, n.burnin, n.thin,
#require(R2WinBUGS)
sims.files <- paste("CODAchain", 1:n.chains, ".txt", sep = "")
index <- read.table("CODAindex.txt", header = FALSE)#, sep = "\t")
if (is.R()) {
# if (is.R()) {
parameter.names <- as.vector(index[, 1])
n.keep <- index[1, 3] - index[1, 2] + 1
}
else {
parameter.names <- row.names(index)
n.keep <- index[1, 2] - index[1, 1] + 1
}
# }
# else {
# parameter.names <- row.names(index)
# n.keep <- index[1, 2] - index[1, 1] + 1
# }
n.parameters <- length(parameter.names)
n.sims <- n.keep * n.chains
sims <- matrix(, n.sims, n.parameters)
Expand Down Expand Up @@ -84,13 +84,13 @@ jags.sims <- function (parameters.to.save, n.chains, n.iter, n.burnin, n.thin,
}
rank.long <- unlist(long.short)
for (i in 1:n.chains) {
if (is.R()) {
# if (is.R()) {
sims.i <- scan(sims.files[i], quiet = TRUE)[2 * (1:(n.keep *
n.parameters))]
}
else {
sims.i <- scan(sims.files[i])[2 * (1:(n.keep * n.parameters))]
}
# }
# else {
# sims.i <- scan(sims.files[i])[2 * (1:(n.keep * n.parameters))]
# }
sims[(n.keep * (i - 1) + 1):(n.keep * i), ] <- sims.i
sims.array[, i, ] <- sims.i
}
Expand Down Expand Up @@ -172,7 +172,7 @@ jags.sims <- function (parameters.to.save, n.chains, n.iter, n.burnin, n.thin,
all
}

if(!is.R()) .subset <- function(x, index) x[index]
# if(!is.R()) .subset <- function(x, index) x[index]


#' function to write bugs model (copied from R2WinBUGS)
Expand All @@ -185,14 +185,14 @@ if(!is.R()) .subset <- function(x, index) x[index]
#'
write.model <- function(model, con = "model.bug", digits = 5)
{
if (is.R()){
# if (is.R()){
model.text <- c("model", replaceScientificNotationR(body(model), digits = digits))
# "[\+\-]?\d*\.?[Ee]?[\+\-]?\d*"
} else {
## In S-PLUS the source code of a function can be obtained with
## as.character(function_name). This omits the "function_name <- function()" piece
model.text <- paste("model", as.character(model))
}
# } else {
# ## In S-PLUS the source code of a function can be obtained with
# ## as.character(function_name). This omits the "function_name <- function()" piece
# model.text <- paste("model", as.character(model))
# }
model.text <- gsub("%_%", "", model.text)
writeLines(model.text, con = con)
}
Expand Down Expand Up @@ -260,9 +260,9 @@ replaceScientificNotationR <- function(bmodel, digits = 5){
confshrink = conv.p$confshrink, n.eff = conv.p$n.eff)
}
else if (trans[i]=="logit"){
if (!is.R()){
#if (!is.R()){
logit <- function (x) { log(x /(1- x)) }
}
#}
conv.p <- conv.par(logit(ai), n.chains, Rupper.keep=Rupper.keep)
conv.p <- list(quantiles = invlogit(conv.p$quantiles),
confshrink = conv.p$confshrink, n.eff = conv.p$n.eff)
Expand Down
11 changes: 3 additions & 8 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -1872,11 +1872,6 @@ s_date_FPR <- function(Rdate,Y,basis="ps",dof=10,...) {
# }


is.R <- function () {
exists("version") && !is.null(vl <- version$language) && vl ==
"R"
}


#' Run `JAGS` from R
#'
Expand Down Expand Up @@ -1950,16 +1945,16 @@ jags2_baker <- function (data, inits, parameters.to.save, model.file = "model.bu
data <- read.jagsdata("jagsdata.txt")
if (is.function(model.file)) {
temp <- tempfile("model")
temp <- if (is.R() || .Platform$OS.type != "windows") {
temp <- if (.Platform$OS.type != "windows") {
paste(temp, "txt", sep = ".")
}
else {
gsub("\\.tmp$", ".txt", temp)
}
write.model(model.file, con = temp)
model.file <- gsub("\\\\", "/", temp)
if (!is.R())
on.exit(file.remove(model.file), add = TRUE)
# if (!is.R())
# on.exit(file.remove(model.file), add = TRUE)
}
jags.call <- if (jags.path == "") {
"jags"
Expand Down

0 comments on commit a20f4bd

Please sign in to comment.