Hi,

we're seeing a problem with a S4Vectors::DataFrame
consisting of numbers and lists where write.table() 
introduces "\n" linebreaks that render the written CSV 
to be broken and unreadable.

The minimum example is:

  library(S4Vectors)
  l <- list(list(1), list(as.character(2:99)), list(3))
  m <- matrix(1:9, nrow=3, ncol=3)
  df <- cbind(DataFrame(m), DataFrame(do.call(rbind, l)))
  write.table(df)

This results in

  V1" "V2" "V3" "V1.1"
  "1" 1 4 7 1
  "2" 2 5 8 c("2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", 
"14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", 
"27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", 
"40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", 
"53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63", "64", "65", 
"66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", 
"79", "80", "81", "82", "83", "84", "85", "86", 
=>"87", "88", "89", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99")
  "3" 3 6 9 3

where the second row is line-wrapped after the "86",
and the next line starts with "87" and the rest of the second row. 
What we also observe is that as.character() of the offending cell 
indeed contains a "\n" at an unexpected place:

  > as.character(df[2,4])
  [1] "c(\"2\", [...], \"85\", \"86\", \n\"87\", \"88\", [...], \"99\")"

This happens for both R-devel 2018-10-17 and S4Vectors_0.19.22
as well as R-3.4.4 with S4Vectors_0.16.0
It affects us in 
https://github.com/workflow4metabolomics/xcms/issues/116#issuecomment-432684024

Any ideas ?

Yours, 
Steffen


-- 

IPB Halle                    AG Massenspektrometrie & Bioinformatik
Dr. Steffen Neumann          http://www.IPB-Halle.DE
Weinberg 3                   http://msbi.bic-gh.de
06120 Halle                  Tel. +49 (0) 345 5582 - 1470
                                  +49 (0) 345 5582 - 0
sneumann(at)IPB-Halle.DE     Fax. +49 (0) 345 5582 - 1409

_______________________________________________
Bioc-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/bioc-devel

Reply via email to