Re: [R] dead code removal

2011-07-19 Thread Juan Carlos Borrás
Ideally you'd have the next two items available: - tests that ensure that your code carries out what it should and as it should. - a coverage analysis tool that reports what parts of your code have been and have not been executed by your tests above. Neither of those are mandatory though, but they

Re: [R] tm: Read a single text file into a corpus as single document?

2011-07-19 Thread Juan Carlos Borrás
Some hints: list.files() will return the list of files in a directory readLines() will allow you to load text files as vectors of lines strsplit() will allow you to break lines into words c(x,y) concatenates vectors x and y ; x <- c(x,y) appends vector y to x unique() will allow you to get rid of r

Re: [R] Gaussian low-pass filter

2011-07-12 Thread Juan Carlos Borrás
gfcoeffs <- function(s, n) { t <- seq(-n,n,1) ## assuming 2*n+1 taps return ( exp(-(t^2/(2*s^2)))/sqrt(2*pi*s^2) ) } 2011/6/29 Martin Wilkes : > I want to filter my time series with a low-pass filter using a Gaussian > smoothing function defined as: > > w(t) = (2πσ^2)^0.5  exp(-t^2/2σ^2) > > I

Re: [R] A masked function is a masked function by any other name

2011-06-28 Thread Juan Carlos Borrás
Ops! Thank-you Duncan for clarifying the 2 vs. 3 colon difference and a couple of other things. Working like a charm now. Cheers, jcb! > If you are using ::: (three colons), then you may be looking into the > unexported functions in log4r.  The only normal way to see unexported > functions is to u

[R] A masked function is a masked function by any other name

2011-06-28 Thread Juan Carlos Borrás
Dear all, It looks like I do not grasp the concept of masked functions enough as to solve this trivial problem. The code that replicates the problem (a source code tree that realizes a R package actually) is under github so one can call it clone it easily from the command line (though more experien

[R] The simplest bar graph with ggplot is difficult to realize

2011-06-08 Thread Juan Carlos Borrás
Dear all, What is the simplest way of producing a bar graph using ggplot but avoiding calling qplot? That is, given: d <- data.frame(x=seq(1,5), y=seq(1,5)) Why does the following line return an error? ggplot(d, aes(x=x, y=y)) + stat_identity() + geom_bar(bindwidth=1) Thanks in advance, jcb! __

Re: [R] transform() on selective names. Is it possible?

2011-04-08 Thread Juan Carlos Borrás
# The code demonstrating the final version I am going to use is as follows rm(list=ls()) # Beware of this one so it doesn't spoil your workspace N <- 100 M <- 2 x <- matrix(data=rnorm(N*M, 0, 3)-10, ncol=M, nrow=N) y <- matrix(c(1,-2,-2,1), ncol=M, nrow=M) z <- data.frame(x %*% y) colnames(z) <-

Re: [R] Avoiding a loop

2011-04-08 Thread Juan Carlos Borrás
Kenn, I find your solution more elegant. 2011/4/8 Kenn Konstabel : > 2011/4/8 Juan Carlos Borrás : >> #Use the indexes of S in a sapply function. >> >> N <- 10 >> S <- sample(c(0,1), size=N, replace=TRUE) >> v1 <- sapply(c(1:N-1), function(i) S[i]&

Re: [R] Avoiding a loop

2011-04-07 Thread Juan Carlos Borrás
#Use the indexes of S in a sapply function. N <- 10 S <- sample(c(0,1), size=N, replace=TRUE) v1 <- sapply(c(1:N-1), function(i) S[i]&&S[i+1]) # Then v2 <- (P > m) # And I guess you can fill up the rest. Beware of the boundary condition (the NA in v1) Cheers, jcb! ___ http:/

Re: [R] transform() on selective names. Is it possible?

2011-04-07 Thread Juan Carlos Borrás
"coln" #end code What I want is to know whether I can customize the column name of the result of the transform() call. Your hint is fantastic, thanks there, but I keep getting into that particular pattern of computation over and over and I wonder if it's possible to skip a column c

[R] transform() on selective names. Is it possible?

2011-04-07 Thread Juan Carlos Borrás
Hi all, I am whitening my data: # code begins N <- 300 M <- 2 x <- matrix(data=rnorm(N*M, 0, 3)-10, ncol=M, nrow=N) y <- matrix(c(1,-2,-2,1), ncol=M, nrow=M) z <- data.frame(x %*% y) colnames(z) <- c('x','y') par(mfrow=c(1,3)) plot(z, pch=5, col="blue") whiten <- function(x) { (x-mean(x))/sd(x) }

[R] Is it possible to run unit tests after a package installation?

2011-03-31 Thread Juan Carlos Borrás
Dear all, I'm deep into Chambers' SoDA and R-exts.html but I can't find all answers. The thing is that I would like to run my unit tests right after a package installation. That is while the command "R CMD check " runs all files named /tests/*.R (so unit tests can be placed there) I wonder if it is