[R] Mysterious issues with reading text files from R in ArcGIS and Excel

Duncan Murdoch murdoch.duncan at gmail.com
Mon Mar 4 18:22:08 CET 2013


On 04/03/2013 11:15 AM, Kerry wrote:
> I realize my command code is not writing a CSV file, I already pointed 
> out that CSV file seems to work OK but not in the TXT format.

Sorry.  In that case, I think you really do have to go to R-sig-Geo to 
find someone who knows about ArcGIS.

Duncan Murdoch

>  Regardless of that, there should be no problems in ArcGIS in reading 
> the date column - in ArcGIS it will simply recognize it as a text 
> field by default.  As I said in my initial posting, when I use other 
> programs to create a text file (say textpad,wordpad, notepad or excel) 
> and bring the txt file into ArcGIS, there is no dropping of the 
> information - it doesn't turn the column into NA's.  It only does this 
> when I try to add text files that were generated from using the 
> write.table or write.csv.
>
> Any thoughts at to explain why I get 2 new columns of data in either 
> the CSV format or the TXT format?
> ~K
>
>
> ------------------------------------------------------------------------
>
> On 04/03/2013 10:52 AM, Kerry wrote:
> > Here's the first 5 lines of my dataset:
> >
> > structure(list(id = structure(c(1L, 1L, 1L, 1L, 1L), .Label = 
> c("F07001",
> > "F07002", "F07003", "F07004", "F07005", "F07006", "F07008", "F07009",
> > "F07010", "F07011", "F07014", "F07015", "F07017", "F07018", "F07019",
> > "F07020", "F07021", "F07022", "F07023", "F07024", "F10001", "F10002",
> > "F10004", "F10008", "F10009", "F10010", "F10012", "F10013", "F10014",
> > "F98015", "M07007", "M07012", "M07013", "M07016", "M10007", "M10011",
> > "M10015"), class = "factor"), x = c(1482445L, 1481274L, 1481279L,
> > 1481271L, 1480849L), y = c(6621768L, 6619628L, 6619630L, 6619700L,
> > 6620321L), date = structure(c(1173085253, 1173092441, 1173099672,
> > 1173106839, 1173114055), class = c("POSIXct", "POSIXt"), tzone = ""),
> >    R1dmed = c(2498.29727014221, 657.102921923195, 660.356911071581,
> >    620.139702002702, 378.186792471657), R1dmean = c(2498.29727014221,
> >    657.102921923195, 660.356911071581, 620.139702002702, 
> 378.186792471657
> >    ), R1error = c(FALSE, FALSE, FALSE, FALSE, FALSE), R2error = c(FALSE,
> >    FALSE, FALSE, FALSE, FALSE)), .Names = c("id", "x", "y",
> > "date", "R1dmed", "R1dmean", "R1error", "R2error"), row.names = c(NA,
> > 5L), class = "data.frame")
> >
> > and here's the code I wrote for this file:
> >
> > write.table(test, "D:/MooseEncounters/locations/Individual/test.txt")
>
> That's not a CSV file, it is being written with a blank as separator.  
> Since it also has blanks in the formatted POSIXct column, you're very 
> likely to run into problems reading it.
>
> Use write.csv(test, "test.csv") and you'll have fewer problems.  If 
> you want tab-delimited columns instead, you'll need to specify that in 
> the write.table call.
>
> Duncan Murdoch
>
>
>
>
>



More information about the R-help mailing list