Ng Stanley
2008-Apr-26 03:28 UTC
[R] 3 questions: debug R script, multi-level sorts, and multi-gsub
Hi, 1) I ran a script say test.R. It ran and terminated with an error. However, I am not sure where the error occur.> source("test.R")Loading required package: tools Welcome to Bioconductor Vignettes contain introductory material. To view, type 'openVignette()'. To cite Bioconductor, see 'citation("Biobase")' and for packages 'citation(pkgname)'. Error: subscript out of bounds 2) I have looked deeply into R, but can't fine multi-level sorts. 3) I have a vector of words, several of which need to be replaced by different unique words. I am using multi-lines of gsub, is there any elegant alternative ? [[alternative HTML version deleted]]
Gabor Grothendieck
2008-Apr-26 04:04 UTC
[R] 3 questions: debug R script, multi-level sorts, and multi-gsub
When it stops with the error you can issue a
traceback()
command or run the script with echo=TRUE:
source("test.R", echo = TRUE, max = 1000)
On Fri, Apr 25, 2008 at 11:28 PM, Ng Stanley <stanleyngkl at gmail.com>
wrote:> Hi,
>
> 1) I ran a script say test.R. It ran and terminated with an error. However,
> I am not sure where the error occur.
>
> > source("test.R")
> Loading required package: tools
>
> Welcome to Bioconductor
>
> Vignettes contain introductory material. To view, type
> 'openVignette()'. To cite Bioconductor, see
> 'citation("Biobase")' and for packages
'citation(pkgname)'.
> Error: subscript out of bounds
> 2) I have looked deeply into R, but can't fine multi-level sorts.
>
> 3) I have a vector of words, several of which need to be replaced by
> different unique words. I am using multi-lines of gsub, is there any
elegant
> alternative ?
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
David Winsemius
2008-Apr-26 12:37 UTC
[R] 3 questions: debug R script, multi-level sorts, and multi-gsub
"Ng Stanley" <stanleyngkl at gmail.com> wrote in news:462b7fdd0804252028w4901ae25v11d53161207d139c at mail.gmail.com:> 2) I have looked deeply into R, but can't fine multi-level sorts.At the top of the help page for sort... "Sort (or order) a vector or factor (partially) into ascending (or descending) order. For ordering along more than one variable, e.g., for sorting data frames, see _order_. " In the examples on the order page, it shows what I suspect you mean by a multilevel sort (although you offer no examples).> (ii <- order(x <- c(1,1,3:1,1:4,3), y <- c(9,9:1), z <-c(2,1:9)))[1] 6 5 2 1 7 4 10 8 3 9> dd <- transform(data.frame(x,y,z),+ z = factor(z, labels=LETTERS[9:1]))> ddx y z 1 1 9 H 2 1 9 I 3 3 8 H 4 2 7 G 5 1 6 F 6 1 5 E 7 2 4 D 8 3 3 C 9 4 2 B 10 3 1 A> dd[ order(x, -y, z) ,]x y z 2 1 9 I 1 1 9 H 5 1 6 F 6 1 5 E 4 2 7 G 7 2 4 D 3 3 8 H 8 3 3 C 10 3 1 A 9 4 2 B -- David Winsemius> > 3) I have a vector of words, several of which need to be replaced by > different unique words. I am using multi-lines of gsub, is there any > elegant alternative ? > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html and provide commented, > minimal, self-contained, reproducible code. >