Dear listers, previous plain text was still more messy,
Here a trial hopefully better...
I encountered an issue with a CSV file that was imported correctly but
could not be re-imported correctly after being written with R. This is
probably because geographical coordinates were imported? as character?in
degrees, minutes and seconds (DMS), which includes " (quotation mark)
for the seconds.
Below a reproducible example:
db <- structure(list(lon = c(6.228561, 6.22532, 6.2260499999999999,
6.2267789999999996, 6.2224659999999998, 6.2209430000000001), latdms =
c("47?12'28.36\"N", "47?12'33.46\"N", "47?12'28.37\"N",
"47?12'27.48\"N", "47?12'31.31\"N", "47?12'33.15\"N"), londms =
c("6?13'42.82\"E", "6?13'31.15\"E", "6?13'33.78\"E", "6?13'36.40\"E",
"6?13'20.88\"E", "6?13'15.39\"E"), fusutmn = c(32L, 32L, 32L, 32L, 32L,
32L)), row.names = c(NA, 6L), class = "data.frame")
> db
write.table(db, file = "db.txt", row.names = FALSE, quote = FALSE, sep =
"\t")
db_import<-read.delim("db.txt")
> db_import
As you can see it, latdms and londms are now collapsed and all the
columns on the right? have shifted to the left. I get the same issue
with ; as a separator.
I could not find a workaround...
Any hint appreciated,
Patrick
trouble with exporting a data.frame with " (quotation mark) in some columns into a tab delimited file, then importing the file
8 messages · Bert Gunter, Ben Bolker, Ivan Krylov +2 more
See ?write.table documentation for "qmethod", which needs to be set to "double" to write the data correctly for csv. This is most easily done by using read.csv and write.csv, for which this is the default. Ergo, the following : (using your example)
write.csv(db, file = "test", row.names = FALSE)
## Note: Set row.names = FALSE so an extra column of numeric row names won't be added.
db2 <- read.csv("test") ## read it back in
identical(db2, db)
[1] TRUE Apologies if I have misunderstood and this does not solve your problem. Cheers, Bert On Sun, Sep 14, 2025 at 10:46?AM Patrick Giraudoux
<patrick.giraudoux at univ-fcomte.fr> wrote:
Dear listers, previous plain text was still more messy,
Here a trial hopefully better...
I encountered an issue with a CSV file that was imported correctly but
could not be re-imported correctly after being written with R. This is
probably because geographical coordinates were imported as character in
degrees, minutes and seconds (DMS), which includes " (quotation mark)
for the seconds.
Below a reproducible example:
db <- structure(list(lon = c(6.228561, 6.22532, 6.2260499999999999,
6.2267789999999996, 6.2224659999999998, 6.2209430000000001), latdms =
c("47?12'28.36\"N", "47?12'33.46\"N", "47?12'28.37\"N",
"47?12'27.48\"N", "47?12'31.31\"N", "47?12'33.15\"N"), londms =
c("6?13'42.82\"E", "6?13'31.15\"E", "6?13'33.78\"E", "6?13'36.40\"E",
"6?13'20.88\"E", "6?13'15.39\"E"), fusutmn = c(32L, 32L, 32L, 32L, 32L,
32L)), row.names = c(NA, 6L), class = "data.frame")
> db
write.table(db, file = "db.txt", row.names = FALSE, quote = FALSE, sep =
"\t")
db_import<-read.delim("db.txt")
> db_import
As you can see it, latdms and londms are now collapsed and all the columns on the right have shifted to the left. I get the same issue with ; as a separator. I could not find a workaround... Any hint appreciated, Patrick
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide https://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Or set quote = TRUE (OP is using delim="\t" to export a tab-separated file ...
On 9/14/25 14:05, Bert Gunter wrote:
See ?write.table documentation for "qmethod", which needs to be set to "double" to write the data correctly for csv. This is most easily done by using read.csv and write.csv, for which this is the default. Ergo, the following : (using your example)
write.csv(db, file = "test", row.names = FALSE)
## Note: Set row.names = FALSE so an extra column of numeric row names won't be added.
db2 <- read.csv("test") ## read it back in
identical(db2, db)
[1] TRUE Apologies if I have misunderstood and this does not solve your problem. Cheers, Bert On Sun, Sep 14, 2025 at 10:46?AM Patrick Giraudoux <patrick.giraudoux at univ-fcomte.fr> wrote:
Dear listers, previous plain text was still more messy,
Here a trial hopefully better...
I encountered an issue with a CSV file that was imported correctly but
could not be re-imported correctly after being written with R. This is
probably because geographical coordinates were imported as character in
degrees, minutes and seconds (DMS), which includes " (quotation mark)
for the seconds.
Below a reproducible example:
db <- structure(list(lon = c(6.228561, 6.22532, 6.2260499999999999,
6.2267789999999996, 6.2224659999999998, 6.2209430000000001), latdms =
c("47?12'28.36\"N", "47?12'33.46\"N", "47?12'28.37\"N",
"47?12'27.48\"N", "47?12'31.31\"N", "47?12'33.15\"N"), londms =
c("6?13'42.82\"E", "6?13'31.15\"E", "6?13'33.78\"E", "6?13'36.40\"E",
"6?13'20.88\"E", "6?13'15.39\"E"), fusutmn = c(32L, 32L, 32L, 32L, 32L,
32L)), row.names = c(NA, 6L), class = "data.frame")
> db
write.table(db, file = "db.txt", row.names = FALSE, quote = FALSE, sep =
"\t")
db_import<-read.delim("db.txt")
> db_import
As you can see it, latdms and londms are now collapsed and all the columns on the right have shifted to the left. I get the same issue with ; as a separator. I could not find a workaround... Any hint appreciated, Patrick
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide https://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide https://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Dr. Benjamin Bolker Professor, Mathematics & Statistics and Biology, McMaster University Associate chair (graduate), Mathematics & Statistics Director, School of Computational Science and Engineering * E-mail is sent at my convenience; I don't expect replies outside of working hours.
? Sun, 14 Sep 2025 19:39:58 +0200 Patrick Giraudoux <patrick.giraudoux at univ-fcomte.fr> ?????:
write.table(db, file = "db.txt", row.names = FALSE, quote = FALSE,
sep = "\t")
db_import<-read.delim("db.txt")
Since write.table() had been called with quote=FALSE, you'll need to read the file with quote="" to prevent read.delim() from interpreting the quotes.
Best regards, Ivan
Fantastic Bert ! It works perfect. Now I will dig in a bit to understand how write.csv works... Thank you, Patrick Le 14/09/2025 ? 20:05, Bert Gunter a ?crit?:
See ?write.table documentation for "qmethod", which needs to be set to "double" to write the data correctly for csv. This is most easily done by using read.csv and write.csv, for which this is the default. Ergo, the following : (using your example)
write.csv(db, file = "test", row.names = FALSE)
## Note: Set row.names = FALSE so an extra column of numeric row names won't be added.
db2 <- read.csv("test") ## read it back in
identical(db2, db)
[1] TRUE Apologies if I have misunderstood and this does not solve your problem. Cheers, Bert On Sun, Sep 14, 2025 at 10:46?AM Patrick Giraudoux <patrick.giraudoux at univ-fcomte.fr> wrote:
Dear listers, previous plain text was still more messy,
Here a trial hopefully better...
I encountered an issue with a CSV file that was imported correctly but
could not be re-imported correctly after being written with R. This is
probably because geographical coordinates were imported as character in
degrees, minutes and seconds (DMS), which includes " (quotation mark)
for the seconds.
Below a reproducible example:
db <- structure(list(lon = c(6.228561, 6.22532, 6.2260499999999999,
6.2267789999999996, 6.2224659999999998, 6.2209430000000001), latdms =
c("47?12'28.36\"N", "47?12'33.46\"N", "47?12'28.37\"N",
"47?12'27.48\"N", "47?12'31.31\"N", "47?12'33.15\"N"), londms =
c("6?13'42.82\"E", "6?13'31.15\"E", "6?13'33.78\"E", "6?13'36.40\"E",
"6?13'20.88\"E", "6?13'15.39\"E"), fusutmn = c(32L, 32L, 32L, 32L, 32L,
32L)), row.names = c(NA, 6L), class = "data.frame")
> db
write.table(db, file = "db.txt", row.names = FALSE, quote = FALSE, sep =
"\t")
db_import<-read.delim("db.txt")
> db_import
As you can see it, latdms and londms are now collapsed and all the columns on the right have shifted to the left. I get the same issue with ; as a separator. I could not find a workaround... Any hint appreciated, Patrick
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guidehttps://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
with quote="" I get an error, Yvan
write.table(db, file = "db.txt", row.names = FALSE, quote="", sep = "\t")
Show Traceback Rerun with Debug Errorin write.table(db, file = "db.txt", row.names = FALSE, quote = "", : invalid 'quote' specification Le 14/09/2025 ? 21:13, Ivan Krylov a ?crit?:
? Sun, 14 Sep 2025 19:39:58 +0200 Patrick Giraudoux<patrick.giraudoux at univ-fcomte.fr> ?????:
write.table(db, file = "db.txt", row.names = FALSE, quote = FALSE,
sep = "\t")
db_import<-read.delim("db.txt")
Since write.table() had been called with quote=FALSE, you'll need to read the file with quote="" to prevent read.delim() from interpreting the quotes.
Yeah, _that_ will be educational. read.csv is quite brief... but you may want to read [1] first. [1] https://adv-r.hadley.nz/
On September 14, 2025 12:28:12 PM PDT, Patrick Giraudoux <patrick.giraudoux at univ-fcomte.fr> wrote:
Fantastic Bert ! It works perfect. Now I will dig in a bit to understand how write.csv works... Thank you, Patrick Le 14/09/2025 ? 20:05, Bert Gunter a ?crit?:
See ?write.table documentation for "qmethod", which needs to be set to "double" to write the data correctly for csv. This is most easily done by using read.csv and write.csv, for which this is the default. Ergo, the following : (using your example)
write.csv(db, file = "test", row.names = FALSE)
## Note: Set row.names = FALSE so an extra column of numeric row names won't be added.
db2 <- read.csv("test") ## read it back in
identical(db2, db)
[1] TRUE Apologies if I have misunderstood and this does not solve your problem. Cheers, Bert On Sun, Sep 14, 2025 at 10:46?AM Patrick Giraudoux <patrick.giraudoux at univ-fcomte.fr> wrote:
Dear listers, previous plain text was still more messy,
Here a trial hopefully better...
I encountered an issue with a CSV file that was imported correctly but
could not be re-imported correctly after being written with R. This is
probably because geographical coordinates were imported as character in
degrees, minutes and seconds (DMS), which includes " (quotation mark)
for the seconds.
Below a reproducible example:
db <- structure(list(lon = c(6.228561, 6.22532, 6.2260499999999999,
6.2267789999999996, 6.2224659999999998, 6.2209430000000001), latdms =
c("47?12'28.36\"N", "47?12'33.46\"N", "47?12'28.37\"N",
"47?12'27.48\"N", "47?12'31.31\"N", "47?12'33.15\"N"), londms =
c("6?13'42.82\"E", "6?13'31.15\"E", "6?13'33.78\"E", "6?13'36.40\"E",
"6?13'20.88\"E", "6?13'15.39\"E"), fusutmn = c(32L, 32L, 32L, 32L, 32L,
32L)), row.names = c(NA, 6L), class = "data.frame")
> db
write.table(db, file = "db.txt", row.names = FALSE, quote = FALSE, sep =
"\t")
db_import<-read.delim("db.txt")
> db_import
As you can see it, latdms and londms are now collapsed and all the columns on the right have shifted to the left. I get the same issue with ; as a separator. I could not find a workaround... Any hint appreciated, Patrick
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guidehttps://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide https://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Sent from my phone. Please excuse my brevity.
1 day later
? Sun, 14 Sep 2025 21:31:43 +0200 Patrick Giraudoux <patrick.giraudoux at univ-fcomte.fr> ?????:
Errorin write.table(db, file = "db.txt", row.names = FALSE, quote = "", : invalid 'quote' specification
write.table() and read.table()/read.delim() are a bit asymmetric. In
this case, write.table() needs quote = FALSE, but read.delim() needs
quote = "":
write.table(db, "db.txt", row.names = FALSE, quote = FALSE, sep = "\t")
db_import <- read.delim("db.txt", quote = "")
Best regards, Ivan