[R-pkg-devel] dir() function use in R packages

2020-03-04 Thread Jarrett Phillips
Hi All,

I am updating my R package that is currently on CRAN.

I am looking to have my main package function iterate through some files in
a directory, but am having some issues.  In my function, I do the following
(I might switch to 'replicate()' instead since non-preallocated for loops
can be very slow):

file.names <- dir(path, pattern = ".fas")
for (i in 1:length(file.names)) {
   # read in DNA sequences using 'pegas' package
  seqs <- read.dna(file = file.names[i], format = "fasta")
}

However, I am uncertain how my function should handle the 'path' argument
to dir(). I could provide 'path' as an explicit argument to my function,
but is there a less direct way?

What I'm after is something like 'file.choose()', except for a folder,
rather than a file.

Has anyone implemented something similar in their R packages?

Thanks!

[[alternative HTML version deleted]]

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


Re: [R-pkg-devel] dir() function use in R packages

2020-03-04 Thread Mark Leeds
I think you want file.path(). you can use that to make a directory that
includes a path to it.
See ?file.path for more details. Then,  you can do something like

mydir ,- file.path(whatever)1, whatever2).
setwd(mydir)

but mydir needs to exist before you do that so check existence first using
file.exists().











On Wed, Mar 4, 2020 at 8:22 PM Jarrett Phillips 
wrote:

> Hi All,
>
> I am updating my R package that is currently on CRAN.
>
> I am looking to have my main package function iterate through some files in
> a directory, but am having some issues.  In my function, I do the following
> (I might switch to 'replicate()' instead since non-preallocated for loops
> can be very slow):
>
> file.names <- dir(path, pattern = ".fas")
> for (i in 1:length(file.names)) {
># read in DNA sequences using 'pegas' package
>   seqs <- read.dna(file = file.names[i], format = "fasta")
> }
>
> However, I am uncertain how my function should handle the 'path' argument
> to dir(). I could provide 'path' as an explicit argument to my function,
> but is there a less direct way?
>
> What I'm after is something like 'file.choose()', except for a folder,
> rather than a file.
>
> Has anyone implemented something similar in their R packages?
>
> Thanks!
>
> [[alternative HTML version deleted]]
>
> __
> R-package-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>

[[alternative HTML version deleted]]

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


[R-pkg-devel] Help on Windows CRAN Check

2020-03-04 Thread John Lawson
I see this error on the CRAN Check report

> ### ** Examples
>
> #Definitive Screening Design
> library(daewr)
> set.seed(1234)
> x <- DefScreen(m=5,c=0)
> colnames(x) <- paste("x",1:5,sep="")
> x$y <- 3*x$x1 + 2*x$x2 + 2*x$x4*x$x5 + x$x3^2 + 2*x$x1^2 + rnorm(nrow(x),0,1)
> (z <- HierAFS(x$y,x[,-6],m=5,c=0,step=4,nm1=FALSE ))
 --- FAILURE REPORT --
 --- failure: the condition has length > 1 ---
 --- srcref ---
:
 --- package (from environment) ---
daewr
 --- call from context ---
ihstep(y, x, m, c)
 --- call from argument ---
if (t1 == "I" & t2 == "(") {
iquad = TRUE
}
 --- R stacktrace ---
where 1: ihstep(y, x, m, c)
where 2: eval(expr, pf)
where 3: eval(expr, pf)
where 4: withVisible(eval(expr, pf))
where 5: evalVis(expr)
where 6: capture.output(res <- ihstep(y, x, m, c))
where 7: withCallingHandlers(expr, warning = function(w)
invokeRestart("muffleWarning"))
where 8: suppressWarnings(invisible(capture.output(res <- ihstep(y, x,
m, c
where 9: HierAFS(x$y, x[, -6], m = 5, c = 0, step = 4, nm1 = FALSE)

 --- value of length: 3 type: logical ---
[1] FALSE FALSE FALSE
 --- function from context ---
function (y, des, m, c)
{
lin <- colnames(des)
values <- c("A", "B", "C", "D", "E", "F", "G", "H", "I",
"J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
"U", "V", "W", "X", "Y", "Z")
repl <- c("I(A^2)", "I(B^2)", "I(C^2)", "I(D^2)", "I(E^2)",
"I(F^2)", "I(G^2)", "I(H^2)", "I(I^2)", "I(J^2)", "I(K^2)",
"I(L^2)", "I(M^2)", "I(N^2)", "I(O^2)", "I(P^2)", "I(Q^2)",
"I(R^2)", "I(S^2)", "I(T^2)", "I(U^2)", "I(V^2)", "I(W^2)",
"I(X^2)", "I(Y^2)", "I(Z^2)")
repl.tab <- cbind(values, repl)
if (m == 0) {
quad <- character()
}
else {
indx <- rep(0, m)
for (i in 1:m) {
indx[i] <- match(lin[i], repl.tab[, 1], nomatch = 0)
}
quad <- rep("A", m)
for (i in 1:m) {
quad[i] <- lin[i]
}
quad[indx != 0] <- repl.tab[indx, 2]
quad <- paste(quad, collapse = "+")
}
dat <- data.frame(y = y, des)
lm1 <- lm(y ~ (.)^2, data = dat)
mm <- model.matrix(lm1)
fact <- colnames(mm)
fact <- fact[-1]
fact <- paste(fact, collapse = "+")
mod <- paste(c(fact, quad), collapse = "+")
lm2 <- lm(reformulate(termlabels = mod, response = "y"),
data = dat)
mm <- model.matrix(lm2)
mm <- mm[, 2:ncol(mm)]
trm <- firstm(y, mm)
d1 <- data.frame(y = y, mm[, trm])
t1 <- substr(trm, 1, 1)
t2 <- substr(trm, 2, 2)
t3 <- substr(trm, 3, 3)
iquad = FALSE
if (t1 == "I" & t2 == "(") {
iquad = TRUE
}
hmt <- trm
if (t2 == "") {
nms <- names(d1)
nms[2] <- hmt
names(d1) <- nms
}
m1 <- lm(y ~ (.), data = d1)
result <- summary(m1)
print(result)
return(trm)
}


 --- function search by body ---
Function ihstep in namespace daewr has this body.
 --- END OF FAILURE REPORT --
Fatal error: the condition has length > 1



However on my own computer or on Rforge

I see this:

* checking examples ... OK
* DONE

Status: OK

-- R CMD check results  daewr 1.1-9 
Duration: 1m 1.8s

0 errors v | 0 warnings v | 0 notes v

R CMD check succeeded


I am not sure what the error is or how to correct it. Any help would
be greatly appreciated,

John Lawson

[[alternative HTML version deleted]]

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel