tests/testthat/test_check_num.R

context("Check numeric")

dat_num <- data.frame("year" = c(1990),
                      "season" = c("iceon"),
                      "researcher" = c("John.Doe"),
                      "lakename" = c("Lake H"),
                      "lakeregloc" = c("slkdfj"),
                      "lakecountry" = c("sasdkfj"),
                      "lakearea" = c(458),
                      "lakemeandepth" = c(1000),
                      "lakemaxdepth" = c(490),
                      "lakeelevation" = c("2000"),
                      "watershedarea" = c("asljadk"),
                      "h2oresidence" = c(900),
                      "lakefetch" = c("sdlfjl"),
                      "stationdistance" = c(1.0),
                      "stationdepth" = c(100),
                      "stationname" = c("Cool Station"),
                      "stationlat" = c("49°15'56.8\"N"), 
                      "stationlong" = c("128°24'42.0\"W"), 
                      "multiplestations" = c(NA), 
                      "startday" = c(12), 
                      "startmonth" = c("Jan"), 
                      "startyear" = c(1990), 
                      "endday" = c(03), 
                      "endmonth" = c("Mar"), 
                      "endyear" = c(1990), 
                      "iceduration" = c("sldkfj"), 
                      "periodn" = c(NA), 
                      "samplenarrat" = c(NA), 
                      "sampletype" = c(NA), 
                      "photicdepth" = c("45 2"), 
                      "sampledepth" = c(NA), 
                      "icedepth" = c(NA), 
                      "snowdepth" = c(NA), 
                      "icenarrat" = c(NA), 
                      "sidata" = c(NA), 
                      "fadata" = c(NA), 
                      "gutdata" = c(NA), 
                      "foodwebnarrat" = c(NA), 
                      "watertemp" = c(NA), 
                      "airtemp" = c(NA), 
                      "averadiation" = c(NA),
                      "avesecchidepth" = c(NA),
                      "avetotphos" = c(NA), 
                      "maxtotphos" = c(NA), 
                      "avetotdissphos" = c(NA), 
                      "maxtotdissphos" = c(NA), 
                      "avetotnitro" = c(NA), 
                      "maxtotnitro" = c(NA), 
                      "avetotdissnitro" = c(NA), 
                      "maxtotdissnitro" = c(NA), 
                      "avetotdoc" = c(NA), 
                      "maxtotdoc" = c(NA), 
                      "avesuva" = c(NA), 
                      "maxsuva" = c(NA), 
                      "avecolor" = c(NA), 
                      "maxcolor" = c(NA), 
                      "avechla" = c(NA), 
                      "maxchla" = c(NA), 
                      "waterchemnarrat" = c(NA),
                      "profiles" = c(NA),
                      "avephytoppr" = c(NA), 
                      "maxphytoppr" = c(NA), 
                      "phytopprunit" = c(NA), 
                      "phytopprnarrat" = c(NA), 
                      "phytomethod" = c(NA), 
                      "avephytomass" = c(NA), 
                      "maxphytomass" = c(NA), 
                      "avephytocount" = c("1325874"), 
                      "maxphytocount" = c("1362358"), 
                      "propchloro" = c(NA), 
                      "propcrypto" = c(NA), 
                      "propcyano" = c(NA), 
                      "propdiatom" = c(NA), 
                      "propdino" = c(NA), 
                      "propotherphyto" = c(NA), 
                      "aveciliamass" = c(NA), 
                      "maxciliamass" = c(NA), 
                      "aveciliacount" = c(NA), 
                      "maxciliacount" = c(NA), 
                      "avehnfmass" = c(NA), 
                      "maxhnfmass" = c(NA), 
                      "avehnfcount" = c(NA), 
                      "maxhnfcount" = c(NA), 
                      "zoopmethod" = c(NA), 
                      "avezoopmass" = c(NA), 
                      "maxzoopmass" = c(NA), 
                      "avezoopcount" = c(NA), 
                      "maxzoopcount" = c(NA), 
                      "propdaphnia" = c(NA), 
                      "propothercladoc" = c(NA), 
                      "propcyclopoid" = c(NA), 
                      "propcalanoid" = c(NA), 
                      "proprotifer" = c(NA), 
                      "propotherzoop" = c(NA), 
                      "avebactcount" = c(NA), 
                      "maxbactcount" = c(NA), 
                      "avebactprod" = c(NA), 
                      "maxbactprod" = c(NA), 
                      "bactprodunit" = c(NA), 
                      "bactprodmethod" = c(NA), 
                      "bactcompnarrat" = c(NA), 
                      "bensubstrate" = c(NA), 
                      "avebenalgalmass" = c(NA), 
                      "maxbenalgalmass" = c(NA), 
                      "avebenchla" = c(NA), 
                      "maxbenchla" = c(NA), 
                      "macrophytemass" = c(NA), 
                      "benamphdens" = c(NA), 
                      "bengastrodens" = c(NA), 
                      "benbivalvedens" = c(NA), 
                      "beninsectdens" = c(NA), 
                      "benoligodens" = c(NA), 
                      "fishnarrat" = c(NA),
                      "cvradiation" = c(NA),
                      "cvsecchidepth" = c(NA),
                      "cvtotphos" = c(NA),
                      "cvtotdissphos" = c(NA),
                      "cvtotnitro" = c(NA),
                      "cvtotdissnitro" = c(NA),
                      "cvtotdoc" = c(NA),
                      "cvsuva" = c(NA),
                      "cvcolor" = c(NA),
                      "cvchla" = c(NA),
                      "cvphytomass" = c(NA),
                      "cvphytocount" = c(NA),
                      "cvciliamass" = c(NA),
                      "cvciliacount" = c(NA),
                      "cvhnfmass" = c(NA),
                      "cvhnfcount" = c(NA),
                      "cvzoopmass" = c(NA),
                      "cvzoopcount" = c(NA),
                      "cvbactcount" = c(NA),
                      "cvbactprod" = c(NA),
                      "cvbenalgalmass" = c(NA),
                      "cvbenchla" = c(NA),      
                      stringsAsFactors = FALSE)

test_that("check_num returns vector of non-numeric or non-logical fields that
should be numeric", {
  expect_true(length(check_num(dat_num)) > 0)
  expect_true(is.vector(check_num(dat_num)))            
})

test_that("fix_num gives warning when fields can't be converted", {
  expect_warning(fix_num(dat_num, coerce = FALSE))
  expect_warning(fix_num(dat_num, coerce = TRUE))
})
karawoo/icetest documentation built on May 18, 2017, 3:25 p.m.