David Kane <David Kane
2001-Oct-04 10:58 UTC
[R] Strange behavior with saved character vectors containing a slash
I am seeing some strange behavior using save on a character vector containing a slash. If this is a bug, I will happily submit it (as a single entry! ;-) ) to r-bugs. Here is an example involving "VIA\B".> version_ platform sparc-sun-solaris2.6 arch sparc os solaris2.6 system sparc, solaris2.6 status major 1 minor 3.0 year 2001 month 06 day 22 language R> ls()character(0)> test <- "VIA\\B" # I proceed the \ with another to escape it. > cat(test, "\n")VIA\B # This is how the string should look.> save(test, ascii = TRUE, file = "here") > remove(list = ls()) > ls()character(0)> load("here") > ls()[1] "test"> cat(test, "\n")VIAB # This is not how the string should look! Where did the \ go?> unlink("here")Any insights would be much appreciated. Regards, Dave Kane -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Peter Dalgaard BSA
2001-Oct-04 11:22 UTC
[R] Strange behavior with saved character vectors containing a slash
"David Kane <David Kane" <a296180 at mica.fmr.com> writes:> I am seeing some strange behavior using save on a character vector containing a > slash. If this is a bug, I will happily submit it (as a single entry! ;-) ) to > r-bugs. Here is an example involving "VIA\B". >It's a bug alright. In saveload.c we have if (x[i] <= 32 || x[i] > 126) { switch(x[i]) { case '\n': fprintf(fp, "\\n"); break; case '\t': fprintf(fp, "\\t"); break; case '\v': fprintf(fp, "\\v"); break; case '\b': fprintf(fp, "\\b"); break; case '\r': fprintf(fp, "\\r"); break; case '\f': fprintf(fp, "\\f"); break; case '\a': fprintf(fp, "\\a"); break; case '\\': fprintf(fp, "\\\\"); break; case '\?': fprintf(fp, "\\?"); break; case '\'': fprintf(fp, "\\'"); break; case '\"': fprintf(fp, "\\\""); break; /* cannot print char in octal mode -> cast to unsigned char first */ default : fprintf(fp, "\\%03o", (unsigned char) x[i]); break; } } Which *looks* like it handles the backslash, but doesn't.... -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._