A station format tells read_station() and prep_visits() which column of a station export holds which standard field, and in which unit. station_format() returns the built-in format of a station type, and optionally writes it as a tab-separated file to use as a template.

station_format(station = c("nedap", "fire"), file = NULL)

Arguments

station

"nedap" or "fire".

file

Optional path. If given, the format is written there as a tab-separated text file (with explanatory comment lines starting with #), which can be edited and passed to read_station(format = ).

Value

A data.table with one row per field: field, column, unit, required and description. Invisibly when file is given.

Format file

A tab-separated text file with a header line field, column, unit (the unit column may be left out). Lines starting with # and empty lines are ignored. For example, for a FIRE export with Chinese headers:

field        column      unit
responder    耳标号      -
location     站号        -
entry_time   日期,进站   -
exit_time    日期,出站   -
trough_in    进站料重    kg
trough_out   出站料重    kg
feed_intake  采食量      kg
weight       体重        kg

  • column: the column name, or its position (6). Several alternatives are separated by | (Tag|耳标号); the first one found is used. Two columns separated by , are joined for a time field: date and clock time (Date,Entry). - or empty means the export does not have the field (only allowed for optional fields).

  • unit: for weight, feed_intake, trough_in, trough_out and topup: kg, g or auto (kg if the median is below 1000, otherwise g). For duration: s or min. For time fields: - (detect YYYY-MM-DD hh:mm:ss or YYYY/MM/DD hh:mm:ss) or a strptime() format such as %d/%m/%Y %H:%M.

Standard fields

FieldTypeStandard unitNEDAPFIRE
respondertextrequiredrequired
locationtextrequiredrequired
entry_timetimeclock time as UTCrequiredrequired
exit_timetimeclock time as UTCoptionalrequired
durationnumbersrequired*—
feed_intakenumbergrequiredrequired
weightnumberkgrequiredrequired
trough_in, trough_outnumberg—required
topupnumberg—optional
breedtextoptionaloptional

\* NEDAP needs duration or exit_time. FIRE computes the duration from entry and exit time; an exit before the entry is a midnight crossing (see prep_visits()).

See also

Examples

station_format("nedap")
#>          field      column   unit required              description
#>         <char>      <char> <char>   <lgcl>                   <char>
#> 1:   responder   responder      -     TRUE       Transponder number
#> 2:    location    location      -     TRUE      Station (feeder) ID
#> 3:  entry_time  visit_time      -     TRUE            Entrance time
#> 4:   exit_time           -      -    FALSE                Exit time
#> 5:    duration    duration      s    FALSE          Occupation time
#> 6: feed_intake feed_intake      g     TRUE Feed intake of the visit
#> 7:      weight      weight   auto     TRUE              Body weight
#> 8:       breed       breed      -    FALSE                    Breed
station_format("fire")
#>           field       column   unit required                     description
#>          <char>       <char> <char>   <lgcl>                          <char>
#>  1:   responder          Tag      -     TRUE              Transponder number
#>  2:    location     Location      -     TRUE             Station (feeder) ID
#>  3:  entry_time   Date,Entry      -     TRUE                   Entrance time
#>  4:   exit_time    Date,Exit      -     TRUE                       Exit time
#>  5: feed_intake     Consumed     kg     TRUE        Feed intake of the visit
#>  6:      weight       Weight     kg     TRUE                     Body weight
#>  7:   trough_in       Ent Wt     kg     TRUE       Trough weight at entrance
#>  8:  trough_out       Ext Wt     kg     TRUE           Trough weight at exit
#>  9:       topup Topup Amount     kg    FALSE Feed dispensed during the visit
#> 10:       breed        breed      -    FALSE                           Breed

# Write a template, edit it, and use it
f <- tempfile(fileext = ".txt")
station_format("fire", file = f)
#> ✔ Station format written to /tmp/Rtmp93iRXT/file1a1632a9a67b.txt
cat(readLines(f), sep = "\n")
#> # tidypptsda station format: FIRE
#> # One line per field, separated by tabs: field, column, unit.
#> # column: column name or position; alternatives with |; date,time joined with ,; - if absent.
#> # unit: kg / g / auto for masses, s / min for duration, - or a strptime format for times.
#> # Required fields: responder, location, entry_time, exit_time, feed_intake, weight, trough_in, trough_out.
#> field	column	unit
#> responder	Tag	-
#> location	Location	-
#> entry_time	Date,Entry	-
#> exit_time	Date,Exit	-
#> feed_intake	Consumed	kg
#> weight	Weight	kg
#> trough_in	Ent Wt	kg
#> trough_out	Ext Wt	kg
#> topup	Topup Amount	kg
#> breed	breed	-
unlink(f)