[R] Suprising behavior of paste or cat?

Russell Pierce rpier001 at ucr.edu
Thu Feb 11 06:20:48 CET 2010

I may be making a simple error, but I've looked at the str() of the
resulting objects and I can't see any obvious reason I'm having the
problem I am having, so I am reaching out to the R-help group.  I am
generating a string in my code.  When I make a slight modification
(add a comma at the end using my "lastcomma" function), I can no
longer successfully write that string to a file.  Specifically, the
resulting file contains only the "ⰱ" character.  This occurs in:
R version 2.10.0 (2009-10-26) & R version 2.10.1 (2009-12-14)
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base
but not in...
R version 2.7.1 (2008-06-23)
attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base
Sample code:
h.long <- 150
task <- c(rep(1,h.long),rep(2,h.long))
ord <- sample(1:length(task))
task <- task[ord]
taskout <- paste(task,collapse=",")
lastcomma <- function(x) {return(paste(x,",",collapse="",sep=""))}
res <- lastcomma(taskout)

Any ideas as to how to avoid this problem would be appriciated as well
as suggestions as to whether this is expected behavior, or whether it
ought to be reported as a bug.


Russell Pierce

More information about the R-help mailing list