"NiwotLTER" <- function (fname = '/Users/thoar/Desktop/C1_temperature.txt') { # The expected structure of the file is as follows: #\log - a history of the file, including persons responsible for, as well as # dates of, creation and modifications #\doc - documentation, i.e., descriptive information and qualifications, with # the following subsections: #TITLE. #ABSTRACT. #INVESTIGATOR. - particulars of contact person, i.e., name, address, phone # number, email address #VARIABLES. - list of key measured and/or derived variables #KEYWORDS. #LOCATION. - location of study, as well as storage locations for samples # and/or original data #TIMING. - study initiation date, study termination date, frequency of # measurements #CITATIONS. - references (in chronological order) that cite data, relate to # methods, etc. #COMMENTS. - information on methodologies (field, laboratory, data # management), exact plot locations, problems, qualifications, # ancillary data, etc. # #\type - e.g., statistical (in columns and rows), graphic, image, etc. #\header - information on the content of data columns, with a subsection for # each column number, and elements within the subsection are: # label= - i.e., the column header # type= - "string", "integer", or "real" # units= - units or "none" # missing value indicator= # minimum= # maximum= # precision= #\data - the "data" con = file(fname,'r') alllines = readLines(con, n=-1) close(con) # The \data block seems to have a blank line after the "\data" # and again after the last of the data block, and the file # then ends with one line of HTML. We want to avoid # incorporating that last line into the read.table part. # # As long as this is 'strict' ... the '4' is the magic number # in the 'maxNobs' declaration. fileend = length(alllines) datastart = charmatch("\\data",alllines) dataend = charmatch("",alllines[datastart:fileend]) maxNobs = dataend - 4 mydata = read.table(fname, skip=datastart, nrows=maxNobs, sep=",", col.names=c("date","Tmax","TmaxFlag","Tmin","TminFlag","Tmean")) z = list(filename=fname, Tmax=mydata[,'Tmax'], Tmin=mydata[,'Tmin'], Tmean=mydata[,'Tmean'], time=mydata[,'date'], nobs=nrow(mydata)) }