sinkovit / Spatial-ecology

Space use software deployed in the Spatial Ecology Gateway
MIT License
2 stars 0 forks source link

cannot load saved file! #147

Closed monaw closed 2 weeks ago

monaw commented 2 weeks ago

it seems when a data file is saved, it cannot be loaded back!

for example 5_bobcats_F4_F9_F13_M10_M15_BBMMinput.csv first 5 entries:

ID,CummulTime,Northing,Easting
F4,0,4234527,258558
F4,300,4231777,259222
F4,1440,4229992,255965
F4,1740,4231788,255459
F4,2100,4233396,255891

loads fine. after it is saved, the file looks like:

"","id","time","ydata","xdata"
"1","F4",0,4234527,258558
"2","F4",300,4231777,259222
"3","F4",1440,4229992,255965
"4","F4",1740,4231788,255459
"5","F4",2100,4233396,255891

but the app will throw an error message "Error : Missing required columns; must have time and lat-long, x-y or UTM"

monaw commented 2 weeks ago

looks like currently the code is renaming the first column to xdata and we end up with 2 xdata columns! debug statement shows the gpsdata at the end of preprocessDataframe() to contain:

     xdata             id                 time            ydata        
 Min.   :   1.0   Length:1580        Min.   :     0   Min.   :4224793  
 1st Qu.: 395.8   Class :character   1st Qu.: 19815   1st Qu.:4231487  
 Median : 790.5   Mode  :character   Median : 39720   Median :4234742  
 Mean   : 790.5                      Mean   : 55348   Mean   :4240917  
 3rd Qu.:1185.2                      3rd Qu.: 72750   3rd Qu.:4252112  
 Max.   :1580.0                      Max.   :209460   Max.   :4258177  
     xdata       
 Min.   :244694  
 1st Qu.:247323  
 Median :252713  
 Mean   :252169  
 3rd Qu.:257614  
 Max.   :259963  
sinkovit commented 2 weeks ago

This is one for me to tackle. I'll address this once I'm done with the NSF annual report, probably tomorrow (7/10)

monaw commented 2 weeks ago

more debugging shows that loadDataframeFromFile() read.csv call will name a header "X" when the column name is blank and then that X column gets renamed to xdata by our code and hence resulting in 2 xdata columns; didn't realize R will allow duplicate column name! so perhaps the fix is not to write the column with no header...

monaw commented 2 weeks ago

oops, that caused a new error "Warning: Error in read.table: duplicate 'row.names' are not allowed" when loading dataset 5_bobcats_F4_F9_F13_M10_M15_BBMMinput.csv, debugging...

monaw commented 2 weeks ago

changing the read.csv() call broke reading other csv files NOT written by write.csv(). instead, i've changed the write.csv() call and that seems to work now