[Rd] chartr better

2007-09-13 Thread Ei-ji Nakama
For example, the following changes are necessary when i convert a
Japanese hiragana into katakana in chattr.

R code:
> chartr("\u3041-\u3093","\u30a1-\u30f3","\u3084\u3063\u305f\u30fc")

--- R-alpha.orig/src/main/character.c   2007-09-05 07:13:27.0 +0900
+++ R-alpha/src/main/character.c2007-09-13 16:10:21.0 +0900
@@ -2041,6 +2041,16 @@
 return(c);
 }

+typedef struct { wchar_t c_old, c_new; } xtable_t;
+static inline int xtable_comp(const xtable_t *a, const xtable_t *b)
+{
+return a->c_old - b->c_old;
+}
+static inline int xtable_key_comp(const wchar_t *a, const xtable_t *b)
+{
+return *a - b->c_old;
+}
+
 SEXP attribute_hidden do_chartr(SEXP call, SEXP op, SEXP args, SEXP env)
 {
 SEXP old, _new, x, y;
@@ -2064,14 +2074,18 @@
 #ifdef SUPPORT_MBCS
 if(mbcslocale) {
 int j, nb, nc;
-wchar_t xtable[65536 + 1], c_old, c_new, *wc;
+xtable_t *xtable;
+int   xtable_cnt;
+wchar_t c_old, c_new, *wc;
 const char *xi, *s;
 struct wtr_spec *trs_old, **trs_old_ptr;
 struct wtr_spec *trs_new, **trs_new_ptr;
-
-for(i = 0; i <= UCHAR_MAX; i++) xtable[i] = i;
+struct wtr_spec *trs_cnt, **trs_cnt_ptr;

 /* Initialize the old and new wtr_spec lists. */
+trs_cnt = Calloc(1, struct wtr_spec);
+trs_cnt->type = WTR_INIT;
+trs_cnt->next = NULL;
 trs_old = Calloc(1, struct wtr_spec);
 trs_old->type = WTR_INIT;
 trs_old->next = NULL;
@@ -2084,6 +2098,7 @@
 if(nc < 0) error(_("invalid multibyte string 'old'"));
 wc = (wchar_t *) R_AllocStringBuffer((nc+1)*sizeof(wchar_t), &cbuff);
 mbstowcs(wc, s, nc + 1);
+wtr_build_spec(wc, trs_cnt); /* use count only */
 wtr_build_spec(wc, trs_old);

s = translateChar(STRING_ELT(_new, 0));
@@ -2096,38 +2111,54 @@
 /* Initialize the pointers for walking through the old and new
wtr_spec lists and retrieving the next chars from the lists.
 */
+trs_cnt_ptr = Calloc(1, struct wtr_spec *);
+*trs_cnt_ptr = trs_cnt->next;
+   for( xtable_cnt = 0 ; wtr_get_next_char_from_spec(trs_cnt_ptr)
;xtable_cnt++ );
+   Free(trs_cnt_ptr);
+   xtable = (xtable_t *)R_alloc(xtable_cnt+1,sizeof(xtable_t));
+
 trs_old_ptr = Calloc(1, struct wtr_spec *);
 *trs_old_ptr = trs_old->next;
 trs_new_ptr = Calloc(1, struct wtr_spec *);
 *trs_new_ptr = trs_new->next;
-for(;;) {
+for(i=0;;i++) {
 c_old = wtr_get_next_char_from_spec(trs_old_ptr);
 c_new = wtr_get_next_char_from_spec(trs_new_ptr);
 if(c_old == '\0')
 break;
 else if(c_new == '\0')
 error(_("'old' is longer than 'new'"));
-else
-xtable[c_old] = c_new;
+else{
+xtable[i].c_old=c_old;
+xtable[i].c_new=c_new;
+   }
 }
+
 /* Free the memory occupied by the wtr_spec lists. */
 wtr_free_spec(trs_old);
 wtr_free_spec(trs_new);
 Free(trs_old_ptr); Free(trs_new_ptr);

+qsort(xtable, xtable_cnt, sizeof(xtable_t),
+  (int(*)(const void *, const void *))xtable_comp);
+
 n = LENGTH(x);
 PROTECT(y = allocVector(STRSXP, n));
 for(i = 0; i < n; i++) {
 if (STRING_ELT(x,i) == NA_STRING)
 SET_STRING_ELT(y, i, NA_STRING);
 else {
+xtable_t *tbl;
 xi = translateChar(STRING_ELT(x, i));
 nc = mbstowcs(NULL, xi, 0);
 if(nc < 0)
 error(_("invalid input multibyte string %d"), i+1);
 wc = (wchar_t *)
R_AllocStringBuffer((nc+1)*sizeof(wchar_t), &cbuff);
 mbstowcs(wc, xi, nc + 1);
-for(j = 0; j < nc; j++) wc[j] = xtable[wc[j]];
+for(j = 0; j < nc; j++)
+if (tbl = bsearch(&wc[j], xtable, xtable_cnt,
sizeof(xtable_t),
+  (int(*)(const void *, const
void *))xtable_key_comp))
+wc[j]=tbl->c_new;
 nb = wcstombs(NULL, wc, 0);
 cbuf = CallocCharBuf(nb);
 wcstombs(cbuf, wc, nb + 1);

-- 
EI-JI Nakama  <[EMAIL PROTECTED]>
"\u4e2d\u9593\u6804\u6cbb"  <[EMAIL PROTECTED]>

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


[Rd] julian: origin argument does not accept POSIXlt objects (PR#9908)

2007-09-13 Thread lore
Full_Name: Rene Locher
Version: 2.5.1 (2007-06-27) 
OS: i386-pc-mingw32
Submission from: (NULL) (160.85.231.54)


julian(as.POSIXlt("1999-2-1"),origin=as.POSIXlt("1999-1-1"))
 ^
gives error:
Error in julian.POSIXt(as.POSIXlt("1999-2-1"), origin = as.POSIXlt("1999-1-1"))
: 
'origin' must be of length one

julian(as.POSIXlt("1999-2-1"),origin=as.POSIXct("1999-1-1"))
works perfect!

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


[Rd] RFE: Add "..." args to barplot()'s xyrect() function calls

2007-09-13 Thread Marc Schwartz
Hi all,

In referencing this thread:

  https://stat.ethz.ch/pipermail/r-help/2007-September/140702.html

the current barplot.default() function includes an internal function
called xyrect() to draw the bars.  

The xyrect() function definition provides for "..." args, however the
actual function calls do not include "..." args. Thus any inline graphic
pars specified in the barplot() call are not passed.

A patch file against the current SVN barplot.r is attached to modify the
three locations in which called xyrect() is called to add "..." args to
each.

Thanks,

Marc Schwartz

--- barplot.R	2007-09-13 08:21:46.0 -0500
+++ barplotRFE.R	2007-09-13 08:23:27.0 -0500
@@ -143,7 +143,7 @@
 	xyrect(rectbase + offset, w.l, c(height) + offset, w.r,
 		   horizontal = horiz,
 		   angle = angle, density = density,
-   col = col, border = border)
+   col = col, border = border, ...)
 	else {
 	## noInside <- NC > 1 && !inside # outside border, but not inside
 	## bordr <- if(noInside) 0 else border
@@ -151,10 +151,10 @@
 		xyrect(height[1:NR, i] + offset[i], w.l[i],
 		   height[ -1,  i] + offset[i], w.r[i],
 		   horizontal = horiz, angle = angle, density = density,
-		   col = col, border = border)# = bordr
+		   col = col, border = border, ...)# = bordr
 		## if(noInside)
 		##  xyrect(min(height[, i]), w.l[i], max(height[, i]), w.r[i],
-		##	   horizontal = horiz, border= border)
+		##	   horizontal = horiz, border= border, ...)
 	}
 	}
 	if (axisnames && !is.null(names.arg)) { # specified or from {col}names
__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Overriding optimisation flags

2007-09-13 Thread Ernest Turro
Dear all,

If one specifies, say, "PKG_CXXFLAGS= -O3" in a Makevars file, it  
will not make a difference to how the code is compiled if -O2 is  
specified in $R_HOME/etc/Makeconf. This is because PKG_CXXFLAGS is  
prepended to the corresponding flags in $R_HOME/etc/Makeconf instead  
of being appended and gcc only uses the last optimisation flag  
specified. As a result, one has to use targets in Makevars, which  
adds unnecessary complication to the whole process. Would it be  
possible to ensure PKG_CXXFLAGS & co.  are appended instead of  
prepended to the default flags and, if not, is there an easier  
workaround than specifying targets? (targets are easy enough under  
unix, but seems a bit more complicated under windows...)

Thanks!

E

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


[Rd] Jobs in Seattle

2007-09-13 Thread Robert Gentleman
Hi,
   As many of you will realize, Seth is going to be leaving us (pretty 
much immediately).  So we will be looking to replace him. In addition,
Martin Morgan is going to be moving into another role as well, one that 
will require an assistant.  In addition, I am looking for at least one 
post-doc (preferably with an interest in sequence related work).

   If any of these interest you, please check out the job descriptions
at:
http://www.fhcrc.org/about/jobs/

  and you can get some idea of salary level as well

  You can feel free to ask me about either the lead programmer job, or 
the post doc and should probably direct questions about the 
bioinformatics position to Martin.

   All applications must go through the FHCRC web site.

  thanks
Robert



-- 
Robert Gentleman, PhD
Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M2-B876
PO Box 19024
Seattle, Washington 98109-1024
206-667-7700
[EMAIL PROTECTED]

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