OpenDendro / dplR

This is the dev site for the dplR package in R
37 stars 14 forks source link

read.rwl() modify search for csv file format #16

Closed chguiterman closed 1 year ago

chguiterman commented 1 year ago

When reading files with headers, such as this one on the ITRDB, there may be a comma (",") in the site name that read.rwl() will incorrectly assume is part of the file formatting, and assume it's a .csv file.

> read.rwl("https://www.ncei.noaa.gov/pub/data/paleo/treering/measurements/northamerica/usa/nm589.rwl")
Attempting to automatically detect format.
Detected a csv file.
Error in scan(file = file, what = what, sep = sep, quote = quote, dec = dec,  : 
  line 1 did not have 2 elements

The issue is located on line 51 of read.rwl():

if(grepl(",", l1)){
                   cat(gettext("Detected a csv file.\n",
                               domain="R-dplR"))
                   csv2rwl(fname, ...)
                 }

where l1 could be replaced to look for a comma within the text block obtained for the tridas format (line 44),

if(any(grepl(",", more.lines))){
                   cat(gettext("Detected a csv file.\n",
                               domain="R-dplR"))
                   csv2rwl(fname, ...)
                 }

resulting in this ITRDB file being correctly identified as Tucson format:

read.rwl("https://www.ncei.noaa.gov/pub/data/paleo/treering/measurements/northamerica/usa/nm589.rwl")
Attempting to automatically detect format.
Assuming a Tucson format file.
There appears to be a header in the rwl file
[1] 0
There are 56 series
AndyBunn commented 1 year ago

Ah. Thanks for that. I will get that into the master branch.