Skip to contents

A function that both checks and prepares a data.frame for use in the trackSpp function.

Usage

checkDat(
  dat,
  inv = NULL,
  species = "Species",
  site = "Site",
  quad = "Quad",
  year = "Year",
  geometry = "geometry",
  reformatDat = FALSE,
  ...
)

Arguments

dat

An sf data.frame of the same format as grasslandData. It must have columns that contain...

  • a unique identification for each research site in character format with no NAs (the default column name is "Site")

  • species name in character format with no NAs (the default column name is "Species")

  • unique quadrat identifier in character format with no NAs (the default column name is "Quad")

  • year of data collection in integer format with no NAs (the default column name is "Year")

  • an s.f 'geometry' column that contains a polygon or multipolygon data type for each individual observation (the default column name is "geometry")

inv

The name of each element of the list is a quadrat name in 'dat', and the contents of that list element is a numeric vector of all of the years in which that quadrat (or other unique spatial area) was sampled. Make sure this is the years the quadrat was actually sampled, not just the years that have data in the 'dat' argument! This argument allows the function to differentiate between years when the quadrat wasn't sampled and years when there just weren't any individuals of a species present in that quadrat.

species

An optional character string argument. Indicates the name of the column in 'dat' that contains species name data. It is unnecessary to include a value for this argument if the column name is "Species" (default value is 'Species').

site

An optional character string argument. Indicates the name of the column in 'dat' that contains site name data. It is unnecessary to include a value for this argument if the column name is "Site" (default value is 'Site').

quad

An optional character string argument. Indicates the name of the column in 'dat' that contains quadrat name data. It is unnecessary to include a value for this argument if the column name is "Quad" (default is 'Quad').

year

An optional character string argument. Indicates the name of the column in 'dat' that contains data for year of sampling. It is unnecessary to include a value for this argument if the column name is "Year" (default is 'Year').

geometry

An optional character string argument. Indicates the name of the column in 'dat' that contains sf geometry data. It is unnecessary to include a value for this argument if the column name is "geometry" (default is 'geometry').

reformatDat

A TRUE/FALSE argument. If 'FALSE', which is the default value, then checkDat() prints a message that says the 'dat' and 'inv' datasets are ready for use in the trackSpp() function. This message includes any column name arguments that must be included in the trackSpp() function call for these datasets. If 'TRUE', checkDat() returns a list with three elements: a version of 'dat' that has been checked for errors and is ready to be input directly into the trackSpp or assign functions, a version of 'inv' that is checked and ready for input into trackSpp() or assign(), and a character vector called 'userColNames' that has all of the user-defined column names that were used in the original version of 'dat'.

...

Other arguments passed on to methods. Not currently used.

Value

If the 'reformatDat' argument is FALSE (the default), the return of this function is a message that says the 'dat' and 'inv' datasets are ready for use in the trackSpp() function. This message includes any column name arguments that must be included in the trackSpp() function call for these datasets. If the 'reformatDat' argument is TRUE, then checkDat() returns a list that contains versions of 'dat' and 'inv' that are ready to go directly into the trackSpp() or assign() functions. The list has the following elements:

dat

An sf data.frame that has five columns called 'Species', 'Site', 'Quad', 'Year', and 'geometry'. Any additional columns that were present in the version of 'dat' input into the checkDat() function will also be included in this version, although the column names will be appended with "_USER".

inv

A named list. The name of each element of the list is a quadrat name in 'dat', and the contents of that list element is a numeric vector of all of the years in which that quadrat (or other unique spatial area) was sampled. For each list element, the vector of years is in sequential order from oldest to most recent.

userColNames

A named character vector. This vector contains the column names provided by the user for all of the required data columns in the original version of 'dat'. The name of each vector element indicates the type of data that is contained in the column with the name in that vector element. For example, if the 'dat' data.frame input into checkDat() has the names 'Species','location' 'quadrat', 'Year', and 'geometry', then this list element will be a character vector of these values with the names 'species', 'site', 'quad', 'year', and 'geometry'.

Details

This function is used internally in trackSpp and other plantTracker functions to check the 'dat' and 'inv' arguments and ensure that they are in the correct format with the correct column names. checkDat() can also be used independently to check that a data.frame is in the correct format and contains the correct data to be used in the trackSpp() or other plantTracker functions.

Examples

checkDat(dat = grasslandData,
inv = grasslandInventory)
#> The data you put into the 'checkDat()' function for the 'dat' and
#>         'inv' arguments are ready to be used in the 'trackSpp()' function! You
#>         do not need to include any values for the 'species', 'site', 'quad',
#>         'year', and 'geometry' arguments in 'trackSpp()

checkDat(dat = grasslandData,
inv = grasslandInventory,
reformatDat = TRUE)
#> $dat
#> Simple feature collection with 1242 features and 12 fields
#> Geometry type: GEOMETRY
#> Dimension:     XY
#> Bounding box:  xmin: -0.001386579 ymin: -0.001470638 xmax: 1.000536 ymax: 1.001267
#> CRS:           NA
#> First 10 features:
#>                      Species Clone_USER Seedling_USER Stems_USER Basal_USER
#> 117603 Heteropogon contortus          0             0         NA         NA
#> 117604 Heteropogon contortus          0             0         NA         NA
#> 117605 Heteropogon contortus          0             0         NA         NA
#> 117606 Heteropogon contortus          0             0         NA         NA
#> 117607 Heteropogon contortus          0             0         NA         NA
#> 117608 Heteropogon contortus          0             0         NA         NA
#> 117609 Heteropogon contortus          0             0         NA         NA
#> 117610 Heteropogon contortus          0             0         NA         NA
#> 117611 Heteropogon contortus          0             0         NA         NA
#> 117612 Heteropogon contortus          0             0         NA         NA
#>        Type_USER Site Quad Year sp_code_4_USER sp_code_6_USER    Area_USER
#> 117603      poly   AZ  SG2 1922           HECO         HETCON 0.0006140896
#> 117604      poly   AZ  SG2 1922           HECO         HETCON 0.0014183352
#> 117605      poly   AZ  SG2 1922           HECO         HETCON 0.0005743856
#> 117606      poly   AZ  SG2 1922           HECO         HETCON 0.0009549092
#> 117607      poly   AZ  SG2 1922           HECO         HETCON 0.0016950661
#> 117608      poly   AZ  SG2 1922           HECO         HETCON 0.0037240299
#> 117609      poly   AZ  SG2 1922           HECO         HETCON 0.0012574011
#> 117610      poly   AZ  SG2 1922           HECO         HETCON 0.0019521166
#> 117611      poly   AZ  SG2 1922           HECO         HETCON 0.0011659233
#> 117612      poly   AZ  SG2 1922           HECO         HETCON 0.0009111819
#>                              geometry
#> 117603 POLYGON ((0.237747 0.908835...
#> 117604 POLYGON ((0.2833037 0.85959...
#> 117605 POLYGON ((0.008583123 0.449...
#> 117606 POLYGON ((0.1480142 0.46983...
#> 117607 POLYGON ((0.03573306 0.5259...
#> 117608 POLYGON ((0.2441894 0.52689...
#> 117609 POLYGON ((0.2888257 0.51815...
#> 117610 POLYGON ((0.3527891 0.45648...
#> 117611 POLYGON ((0.6749071 0.82646...
#> 117612 POLYGON ((0.4604686 0.76526...
#> 
#> $inv
#> $inv$C5
#> [1] 1936 1937 1938 1939 1940
#> 
#> $inv$D1
#> [1] 1936 1937 1938 1939 1940
#> 
#> $inv$SG2
#> [1] 1922 1923 1924 1925 1926 1927
#> 
#> $inv$SG4
#> [1] 1922 1923 1924 1925 1926 1927
#> 
#> 
#> $userColNames
#>    species       site       quad       year   geometry 
#>  "Species"     "Site"     "Quad"     "Year" "geometry" 
#>