diff --git a/DESCRIPTION b/DESCRIPTION index 36836f8..b1b5e46 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -33,7 +33,6 @@ Imports: uuid Suggests: gt, - here, knitr, nanoparquet, ozmaps, diff --git a/R/check.R b/R/check.R index e103e36..1b3e6b4 100644 --- a/R/check.R +++ b/R/check.R @@ -435,11 +435,9 @@ check_mismatch_code_country <- function(.df, # cli::cli_warn(bullets) # } - - lookup_country <- country_codes$country_name[country_codes$code %in% x] correct_country <- country_codes$country_name - if(lookup_country != df$countryCode[1]){ + if(lookup_country != .df$countryCode[1]){ bullets <- c("Country code in {.field {x}} does not correspond to country.", i = "Did you mean {lookup_country}?" ) diff --git a/R/check_occurrences.R b/R/check_occurrences.R index 60bdf78..6e5fd67 100644 --- a/R/check_occurrences.R +++ b/R/check_occurrences.R @@ -54,8 +54,7 @@ check_dataset <- function(.df){ invisible() # prevent df results from printing with headers # check all checkable fields, save fields & error messages - check_results <- - check_functions_names |> + check_results <- check_functions_names |> map(~ check_all(.x, .df, checkable_fields)) |> bind_rows() @@ -81,7 +80,7 @@ check_dataset <- function(.df){ results_split <- check_results |> unnest(.data$messages) |> mutate( - term = factor(term, levels = unique(term)) # maintain original term order + term = factor(.data$term, levels = unique(.data$term)) # maintain original term order ) |> group_split(.data$term) @@ -264,13 +263,14 @@ check_min_req_dwc <- function(checkable_fields) { # message dwc_spinny_message(glue("Data meets minimum Darwin Core requirements")) - complies_text <- "Data meets minimum Darwin Core requirements" if(isTRUE(is_dwc_compliant)) { + complies_text <- "Data meets minimum Darwin Core requirements" cli::cli_status_clear() cat_line(glue("{col_green(symbol$tick)} {complies_text}")) } else { + noncomplies_text <- "Data does not meet minimum Darwin Core requirements" cli::cli_status_clear() - cat_line(glue("{col_red(symbol$cross)} {complies_text}")) + cat_line(glue("{col_red(symbol$cross)} {noncomplies_text}")) cli_bullets(c(i = "Use `suggest_workflow()` to see more information.")) } diff --git a/R/data_functions.R b/R/data_functions.R index 2124742..5c495e3 100644 --- a/R/data_functions.R +++ b/R/data_functions.R @@ -12,14 +12,14 @@ #' @rdname accepted_terms #' @export occurrence_terms <- function(){ - darwin_core_terms |> + corella::darwin_core_terms |> dplyr::pull(.data$term) } #' @rdname accepted_terms #' @export event_terms <- function(){ - darwin_core_terms |> + corella::darwin_core_terms |> dplyr::filter(.data$class %in% c("Generic", "Event", "Location")) |> dplyr::pull(.data$term) } diff --git a/R/suggest_workflow.R b/R/suggest_workflow.R index d02cc11..d8132e8 100644 --- a/R/suggest_workflow.R +++ b/R/suggest_workflow.R @@ -218,7 +218,8 @@ suggest_functions_message <- function(suggested_functions, # add pipe when there are multiple suggested functions if(length(suggested_functions) > 1) { - suggested_functions_piped <- c(paste0(head(suggested_functions, -1), " |> "), tail(suggested_functions, 1)) + suggested_functions_piped <- c(paste0(utils::head(suggested_functions, -1), " |> "), + utils::tail(suggested_functions, 1)) } else { suggested_functions_piped <- suggested_functions } @@ -273,7 +274,7 @@ additional_functions_message <- function(optional_functions, cli_text(paste0("Based on your matched terms, you can also add to your pipe: ", "\n")) cli_bullets(c("*" = optional_functions_message)) } - cli_bullets(c("i" = col_grey("See all `use_` functions at {.url https://galaxias.ala.org.au/reference/index.html#add-darin-core-terms}"))) + cli_bullets(c("i" = col_grey("See all `use_` functions at http://corella.ala.org.au/reference/index.html#add-rename-or-edit-columns-to-match-darwin-core-terms"))) } @@ -407,30 +408,30 @@ build_req_terms_table <- function(req_terms) { # Unnest & concatenate terms by group missing_results <- req_terms |> select(-"matched") |> - unnest(cols = c(missing)) |> + unnest(cols = c(.data$missing)) |> group_by(.data$term_group) |> mutate( # glue names - missing = ansi_collapse(missing, sep = ", ", last = ", ") + missing = ansi_collapse(.data$missing, sep = ", ", last = ", ") ) |> unique() matched_results <- req_terms |> select(-"missing") |> - unnest(cols = c(matched)) |> + unnest(cols = c(.data$matched)) |> group_by(.data$term_group) |> mutate( # glue names - matched = ansi_collapse(matched, sep = ", ", last = ", ") + matched = ansi_collapse(.data$matched, sep = ", ", last = ", ") ) |> unique() req_terms_message <- missing_results |> full_join(matched_results, - join_by(term_group, result)) |> + join_by("term_group", "result")) |> # remove other Identifier terms if one or more are matched mutate( missing = case_when( - term_group == "Identifier (at least one)" & !is.na(matched) ~ NA, - .default = missing + .data$term_group == "Identifier (at least one)" & !is.na(.data$matched) ~ NA, + .default = .data$missing )) |> # add blank space for correct message formatting tidyr::replace_na(list(missing = stringr::str_pad("-", width = 16, side = "right"), @@ -438,10 +439,10 @@ build_req_terms_table <- function(req_terms) { # Group terms found vs missing pass <- req_terms_message |> - filter(result == "pass") + filter(.data$result == "pass") failed <- req_terms_message |> - filter(result == "fail") + filter(.data$result == "fail") pass_group <- glue("{pass$term_group}") pass_matched <- glue("{pass$matched}") @@ -576,8 +577,8 @@ check_required_terms <- function(user_column_names) { # convert empty row value to NULL result <- all_terms |> mutate( - missing = lapply(missing, function(x) if(identical(x, character(0))) NULL else x), - matched = lapply(matched, function(x) if(identical(x, character(0))) NULL else x) + missing = lapply(.data$missing, function(x) if(identical(x, character(0))) NULL else x), + matched = lapply(.data$matched, function(x) if(identical(x, character(0))) NULL else x) ) return(result) diff --git a/R/use_abundance.R b/R/use_abundance.R index bec730b..19f859d 100644 --- a/R/use_abundance.R +++ b/R/use_abundance.R @@ -116,9 +116,9 @@ check_individualCount <- function(.df, # make sure 0s are tagged as absences in occurrenceStatus absences <- .df |> - select(individualCount, occurrenceStatus) |> - filter(individualCount == 0) |> - mutate(match = individualCount == 0 & occurrenceStatus == "absent") + select("individualCount", "occurrenceStatus") |> + filter(.data$individualCount == 0) |> + mutate(match = .data$individualCount == 0 & .data$occurrenceStatus == "absent") if(any(absences$match == FALSE)) { n_unmatched <- absences |> @@ -186,7 +186,7 @@ check_organismQuantityType <- function(.df, level <- match.arg(level) if(any(colnames(.df) == "organismQuantityType")){ .df |> - select(organismQuantityType) |> + select("organismQuantityType") |> check_is_string(level = level) if (!any(colnames(.df) == "organismQuantity")) { diff --git a/R/use_measurements.R b/R/use_measurements.R index 24f22e4..2be24a7 100644 --- a/R/use_measurements.R +++ b/R/use_measurements.R @@ -38,11 +38,9 @@ use_measurements <- function( nested_df <- .df |> # add row number for id - mutate( - padded_row_number = stringr::str_pad(row_number(), floor(log10(row_number())) + 1, pad = '0') - ) |> + mutate(padded_row_number = sequential_id()) |> # NOTE: Must use group_split to preserve grouping by row, not an unexpected grouping (ie force rowwise) - group_split(row_number(), .keep = FALSE) |> + group_split(dplyr::row_number(), .keep = FALSE) |> purrr::map_dfr( ~ .x |> nest(measurementOrFact = c(padded_row_number, !!!fn_quos))) @@ -53,7 +51,7 @@ use_measurements <- function( result <- nested_df |> dplyr::mutate( measurementOrFact = purrr::map( - measurementOrFact, + .data$measurementOrFact, ~ .x |> pivot_longer(names_to = "column_name", values_to = "measurementValue", diff --git a/R/use_sf.R b/R/use_sf.R index 8c4a32f..0631a1d 100644 --- a/R/use_sf.R +++ b/R/use_sf.R @@ -39,8 +39,7 @@ use_sf <- function( names(fn_quos) <- fn_args fn_quo_is_null <- fn_quos |> - purrr::map(\(user_arg) - rlang::quo_is_null(user_arg)) |> + map(.f = rlang::quo_is_null) |> unlist() # detect sf and handle sf objects @@ -59,28 +58,28 @@ use_sf <- function( } else { - # if geometry arg has been named, save the name - if(!any(fn_quo_is_null)) { + # if geometry arg has been named, save the name + if(!any(fn_quo_is_null)) { - col_name_sfc <- paste0(get_expr(fn_quos$geometry)) # save name + col_name_sfc <- paste0(get_expr(fn_quos$geometry)) # save name - # check if column name is in the dataframe - if(!col_name_sfc %in% colnames(.df)) { - bullets <- c( - "Must specify an existing 'geometry' column.", - x = "Column '{col_name_sfc}' doesn't exist." - ) |> cli_bullets() |> cli_fmt() + # check if column name is in the dataframe + if(!col_name_sfc %in% colnames(.df)) { + bullets <- c( + "Must specify an existing 'geometry' column.", + x = "Column '{col_name_sfc}' doesn't exist." + ) |> cli_bullets() |> cli_fmt() - cli_abort(bullets) - } + cli_abort(bullets) + } - } else { + } else { - # get column name that holds 'geometry' - col_name_sfc <- .df |> - select(which(sapply(.df, class) == 'sfc_POINT')) |> # might be overcomplicating `select(geometry)` - colnames() - } + # get column name that holds 'geometry' + col_name_sfc <- .df |> + select(which(sapply(.df, class) == 'sfc_POINT')) |> # might be overcomplicating `select(geometry)` + colnames() + } } } @@ -94,7 +93,10 @@ use_sf <- function( # Add sf coords if valid check_coords(.df, level = "abort") - result <- col_sf_to_dwc(.df, col_name_sfc, level = level) |> + result <- col_sf_to_dwc(.df, + col_name_sfc + # level = level + ) |> st_drop_geometry() cli_warn("{.field {col_name_sfc}} dropped from data frame.") @@ -133,7 +135,7 @@ check_is_sf <- function(.df, "No geometry detected.", i = "Must supply {.code use_sf()} a dataframe with an {.pkg sf} geometry (i.e. {.code st_POINT})." ) |> cli_bullets() |> cli_fmt() - cli_abort(bullets) + cli_abort(bullets) # FIXME: this ignores 'level' argument } .df } @@ -150,8 +152,7 @@ check_is_point <- function(.df, # enforce POINT geometry if (any(st_geometry_type(.df, by_geometry = FALSE) != "POINT")) { sf_type <- st_geometry_type(.df, by_geometry = FALSE) - cli_abort(".df geometry must be of type 'POINT', not '{sf_type}'.") - + cli_abort(".df geometry must be of type 'POINT', not '{sf_type}'.") # FIXME: this ignores 'level' argument } .df } @@ -193,7 +194,7 @@ check_has_crs <- function(.df, #' @keywords Internal col_sf_to_dwc <- function(.df, col_name, - level = c("inform", "warn", "abort"), + # level = c("inform", "warn", "abort"), # unused call = caller_env() ){ result <- .df |> diff --git a/inst/examples/data/occurrence_exemplar.csv b/inst/examples/data/occurrence_exemplar.csv deleted file mode 100644 index 792b2bb..0000000 --- a/inst/examples/data/occurrence_exemplar.csv +++ /dev/null @@ -1,10 +0,0 @@ -occurrenceID,basisOfRecord,eventDate,endDayOfYear,year,month,day,verbatimEventDate,eventRemarks,scientificName,higherClassification,kingdom,phylum,class,order,family,genus,specificEpithet,infraspecificEpithet,taxonRank,identifiedBy,dateIdentified,nomenclaturalCode,decimalLatitude,decimalLongitude,geodeticDatum,coordinateUncertaintyInMeters,verbatimCoordinates,verbatimCoordinateSystem,georeferencedBy,georeferencedDate,georeferenceProtocol,georeferenceSources,georeferenceVerificationStatus,higherGeography,continent,islandGroup,island,country,countryCode,stateProvince,county,locality,verbatimLocality,locationAccordingTo,type,modified,language,license,references,institutionID,institutionCode,collectionCode,catalogNumber,occurrenceRemarks,recordNumber,recordedBy,organismID,individualCount,organismQuantity,organismQuantityType,establishmentMeans,preparations,otherCatalogNumbers,previousIdentifications -http://arctos.database.museum/guid/CUMV:Amph:11733?seid=2231302,PreservedSpecimen,1926-04,,1926,4,,0/4/1926,day of month unknown,Ambystoma maculatum,Animalia; Chordata; Amphibia; Caudata; Ambystomatidae;,Animalia,Chordata,Amphibia,Caudata,Ambystomatidae,Ambystoma,maculatum,,species,unknown,1926-04,ICZN,42.4566,-76.45442,WGS84,500,42.4566/-76.45442,decimal degrees,unknown,2014-03-03,MaNIS georeferencing guidelines,"NamedPlaceExtent: 1000; Coordinate Source: MaNIS; Georeference Source: Terrain Navigator 7.03, 1:24,000; Georeference Date: 20070808",unverified,"North America, United States, New York, Tompkins County",North America,,,United States,US,New York,Tompkins County,"Ithaca, Forest Home, CU Rifle Range, North side of Fall Creek across from Stevens Suspension Bridge",pond near rifle range,unknown,PhysicalObject,2015-11-13 12:43:50.0,en,http://creativecommons.org/publicdomain/zero/1.0/legalcode,http://arctos.database.museum/guid/CUMV:Amph:11733,http://grbio.org/cool/i64g-wjcr,CUMV,Amphibian specimens,11733,partly hatched,,Collector(s): John R. Greely,http://arctos.database.museum/guid/CUMV:Amph:11733,1,1,individuals,wild caught,egg (formalin),Trapline ID=JRG 1926APR; original identifier=CU Egg 106,Ambystoma maculatum (accepted ID) identified by unknown on 1926-04; method: legacy -http://arctos.database.museum/guid/CUMV:Amph:4335?seid=2239851,PreservedSpecimen,1942-04-17,107,1942,4,17,17/4/1942,,Desmognathus fuscus,Animalia; Chordata; Amphibia; Caudata; Plethodontidae; Desmognathinae;,Animalia,Chordata,Amphibia,Caudata,Plethodontidae,Desmognathus,fuscus,,species,unknown,1942-04-17,ICZN,42.4566,-76.45442,WGS84,500,42.4566/-76.45442,decimal degrees,unknown,2014-03-03,MaNIS georeferencing guidelines,"NamedPlaceExtent: 1000; Coordinate Source: MaNIS; Georeference Source: Terrain Navigator 7.03, 1:24,000; Georeference Date: 20070808",unverified,"North America, United States, New York, Tompkins County",North America,,,United States,US,New York,Tompkins County,"Ithaca, Forest Home, CU Rifle Range, North side of Fall Creek across from Stevens Suspension Bridge","Rifle Range, Fall Cr., Ithaca.",unknown,PhysicalObject,2015-11-13 12:43:50.0,en,http://creativecommons.org/publicdomain/zero/1.0/legalcode,http://arctos.database.museum/guid/CUMV:Amph:4335,http://grbio.org/cool/i64g-wjcr,CUMV,Amphibian specimens,4335,,,Collector(s): Robert M. Roecker,http://arctos.database.museum/guid/CUMV:Amph:4335,1,1,individuals,wild caught,whole organism (unknown),Trapline ID=RMR 1942APR17,Desmognathus fuscus (accepted ID) identified by unknown on 1942-04-17; method: legacy -http://arctos.database.museum/guid/CUMV:Amph:4337?seid=2239852,PreservedSpecimen,1942-04-17,107,1942,4,17,17/4/1942,,Gyrinophilus porphyriticus,Animalia; Chordata; Amphibia; Caudata; Plethodontidae; Plethodontinae;,Animalia,Chordata,Amphibia,Caudata,Plethodontidae,Gyrinophilus,porphyriticus,,species,unknown,1942-04-17,ICZN,42.4566,-76.45442,WGS84,500,42.4566/-76.45442,decimal degrees,unknown,2014-03-03,MaNIS georeferencing guidelines,"NamedPlaceExtent: 1000; Coordinate Source: MaNIS; Georeference Source: Terrain Navigator 7.03, 1:24,000; Georeference Date: 20070808",unverified,"North America, United States, New York, Tompkins County",North America,,,United States,US,New York,Tompkins County,"Ithaca, Forest Home, CU Rifle Range, North side of Fall Creek across from Stevens Suspension Bridge","Rifle Range, Fall Cr., Ithaca.",unknown,PhysicalObject,2015-11-13 12:43:50.0,en,http://creativecommons.org/publicdomain/zero/1.0/legalcode,http://arctos.database.museum/guid/CUMV:Amph:4337,http://grbio.org/cool/i64g-wjcr,CUMV,Amphibian specimens,4337,,,Collector(s): Robert M. Roecker,http://arctos.database.museum/guid/CUMV:Amph:4337,1,1,individuals,wild caught,whole organism (unknown),Trapline ID=RMR 1942APR17,Gyrinophilus porphyriticus (accepted ID) identified by unknown on 1942-04-17; method: legacy -http://arctos.database.museum/guid/CUMV:Amph:4340?seid=2243745,PreservedSpecimen,1942-04-17,107,1942,4,17,17/4/1942,,Eurycea bislineata bislineata,Animalia; Chordata; Amphibia; Caudata; Plethodontidae;,Animalia,Chordata,Amphibia,Caudata,Plethodontidae,Eurycea,bislineata,bislineata,subspecies,unknown,1942-04-17,ICZN,42.4566,-76.45442,WGS84,500,42.4566/-76.45442,decimal degrees,unknown,2014-03-03,MaNIS georeferencing guidelines,"NamedPlaceExtent: 1000; Coordinate Source: MaNIS; Georeference Source: Terrain Navigator 7.03, 1:24,000; Georeference Date: 20070808",unverified,"North America, United States, New York, Tompkins County",North America,,,United States,US,New York,Tompkins County,"Ithaca, Forest Home, CU Rifle Range, North side of Fall Creek across from Stevens Suspension Bridge","Rifle Range, Fall Cr., Ithaca.",unknown,PhysicalObject,2015-11-13 12:43:50.0,en,http://creativecommons.org/publicdomain/zero/1.0/legalcode,http://arctos.database.museum/guid/CUMV:Amph:4340,http://grbio.org/cool/i64g-wjcr,CUMV,Amphibian specimens,4340,,,Collector(s): Robert M. Roecker,http://arctos.database.museum/guid/CUMV:Amph:4340,1,1,individuals,wild caught,whole organism (unknown),Trapline ID=RMR 1942APR17,Eurycea bislineata bislineata (accepted ID) identified by unknown on 1942-04-17; method: legacy -http://arctos.database.museum/guid/CUMV:Amph:4341?seid=2246587,PreservedSpecimen,1942-04-17,107,1942,4,17,17/4/1942,,Plethodon cinereus,Animalia; Chordata; Amphibia; Caudata; Plethodontidae; Plethodontinae;,Animalia,Chordata,Amphibia,Caudata,Plethodontidae,Plethodon,cinereus,,species,unknown,1942-04-17,ICZN,42.4566,-76.45442,WGS84,500,42.4566/-76.45442,decimal degrees,unknown,2014-03-03,MaNIS georeferencing guidelines,"NamedPlaceExtent: 1000; Coordinate Source: MaNIS; Georeference Source: Terrain Navigator 7.03, 1:24,000; Georeference Date: 20070808",unverified,"North America, United States, New York, Tompkins County",North America,,,United States,US,New York,Tompkins County,"Ithaca, Forest Home, CU Rifle Range, North side of Fall Creek across from Stevens Suspension Bridge","Rifle Range, Fall Cr., Ithaca.",unknown,PhysicalObject,2015-11-13 12:43:50.0,en,http://creativecommons.org/publicdomain/zero/1.0/legalcode,http://arctos.database.museum/guid/CUMV:Amph:4341,http://grbio.org/cool/i64g-wjcr,CUMV,Amphibian specimens,4341,,,Collector(s): Robert M. Roecker,http://arctos.database.museum/guid/CUMV:Amph:4341,1,1,individuals,wild caught,whole organism (unknown),Trapline ID=RMR 1942APR17,Plethodon cinereus (accepted ID) identified by unknown on 1942-04-17; method: legacy -http://arctos.database.museum/guid/CUMV:Amph:16004?seid=2329885,PreservedSpecimen,1953-09-27,270,1953,9,27,27-Sep-53,,Rana sylvatica,"Animalia; Chordata; Amphibia; Anura; Ranidae; LeConte, 1825",Animalia,Chordata,Amphibia,Anura,Ranidae,Rana,sylvatica,,species,J. N. Layne,,ICZN,42.4566,-76.45442,WGS84,500,42.4566/-76.45442,decimal degrees,Charles M. Dardia,2014-05-16,MaNIS georeferencing guidelines,"NamedPlaceExtent: 1000; Coordinate Source: MaNIS; Georeference Source: Terrain Navigator 7.03, 1:24,000; Georeference Date: 20070808",checked by collector,"North America, United States, New York, Tompkins County",North America,,,United States,US,New York,Tompkins County,"Ithaca, Forest Home, CU Rifle Range, North side of Fall Creek across from Stevens Suspension Bridge","Ithaca, Cornell University Rifle Range",Charles M. Dardia,PhysicalObject,2015-11-13 12:43:50.0,en,http://creativecommons.org/publicdomain/zero/1.0/legalcode,http://arctos.database.museum/guid/CUMV:Amph:16004,http://grbio.org/cool/i64g-wjcr,CUMV,Amphibian specimens,16004,in mouth of Thamnophis sirtalis,,Collector(s): J. N. Layne,http://arctos.database.museum/guid/CUMV:Amph:16004,1,1,individuals,wild caught,whole organism (isopropanol),,Rana sylvatica (accepted ID) identified by J. N. Layne; method: legacy -http://arctos.database.museum/guid/CUMV:Amph:11618?seid=2241805,PreservedSpecimen,1979-06-02/1979-06-07,,,,,2/6/1979,,Eleutherodactylus eneidae,Animalia; Chordata; Amphibia; Anura; Leptodactylidae; Eleutherodactylinae;,Animalia,Chordata,Amphibia,Anura,Leptodactylidae,Eleutherodactylus,eneidae,,species,unknown,1979-06-02,ICZN,18.302,-65.793,WGS84,,18.302/-65.793,decimal degrees,unknown,2014-03-03,not recorded,Georeference Source: Topozone.com 2007; Georeference Date: 20080430,unverified,"West Indies, United States, Puerto Rico, Greater Antilles",West Indies,Greater Antilles,,United States,US,Puerto Rico,,Mt. Britton Trail,Mt. Britton Trail,unknown,PhysicalObject,2015-10-28 10:33:21.0,en,http://creativecommons.org/publicdomain/zero/1.0/legalcode,http://arctos.database.museum/guid/CUMV:Amph:11618,http://grbio.org/cool/i64g-wjcr,CUMV,Amphibian specimens,11618,,PR 1687,"Collector(s): J. Wilson, R. Thomas",http://arctos.database.museum/guid/CUMV:Amph:11618,1,1,individuals,wild caught,whole organism (isopropanol),Trapline ID=JW 1979JUN02A; collector number=PR 1687,Eleutherodactylus eneidae (accepted ID) identified by unknown on 1979-06-02; method: legacy -http://arctos.database.museum/guid/CUMV:Amph:16023?seid=2660598,PreservedSpecimen,1981-06-01,152,1981,6,1,1-Jun-81,,Masticophis flagellum piceus,Animalia; Chordata; Reptilia; Squamata; Colubridae;,Animalia,Chordata,Reptilia,Squamata,Colubridae,Masticophis,flagellum,piceus,subspecies,Sean Mchugh,,ICZN,32.7038,-109.9191,WGS84,542,32.7038/-109.9191,decimal degrees,Sean Mchugh,2015-07-15,BioGeoMancer,Beogeomancer,unverified,"North America, United States, Arizona, Graham County",North America,,,United States,US,Arizona,Graham County,"Head Soldier Creek, Graham Mts., 9300 ft","Head Soldier Creek, Graham Mts., 9300 ft",Sean Mchugh,PhysicalObject,2015-07-16 12:39:26.0,en,http://creativecommons.org/publicdomain/zero/1.0/legalcode,http://arctos.database.museum/guid/CUMV:Amph:16023,http://grbio.org/cool/i64g-wjcr,CUMV,Amphibian specimens,16023,C.A. Beuchat collector,,Collector(s): unknown,http://arctos.database.museum/guid/CUMV:Amph:16023,1,1,individuals,wild caught,whole organism (mummified),,Masticophis flagellum piceus (accepted ID) identified by Sean Mchugh; method: field -http://arctos.database.museum/guid/CUMV:Amph:16113?seid=2674154,PreservedSpecimen,2011-06-23,174,2011,6,23,23-Jun-11,,Rana (Lithobates) clamitans,"Animalia; Chordata; Amphibia; Anura; Ranidae; Latreille, 1801",Animalia,Chordata,Amphibia,Anura,Ranidae,Rana,(Lithobates) clamitans,,species,Kelly R. Zamudio,,ICZN,43.362,-74.587,WGS84,250,43.362/-74.587,decimal degrees,Charles M. Dardia,2015-09-18,not recorded,GPS,unverified,"North America, United States, New York, Hamilton County",North America,,,United States,US,New York,Hamilton County,"Piseco, 11 km SSW, Powley Road","Powley Rd. Lake Pleasant, NY Adiirondacks",Charles M. Dardia,PhysicalObject,2015-09-18 10:40:34.0,en,http://creativecommons.org/publicdomain/zero/1.0/legalcode,http://arctos.database.museum/guid/CUMV:Amph:16113,http://grbio.org/cool/i64g-wjcr,CUMV,Amphibian specimens,16113,,KZ 3386,Collector(s): Guilherme Becker,http://arctos.database.museum/guid/CUMV:Amph:16113,1,1,individuals,wild caught,whole organism (ethanol),collector number=KZ 3386,Rana (Lithobates) clamitans (accepted ID) identified by Kelly R. Zamudio; method: expert \ No newline at end of file diff --git a/inst/examples/data/westerband_2022_wdate.csv b/inst/extdata/westerband_2022_wdate.csv similarity index 100% rename from inst/examples/data/westerband_2022_wdate.csv rename to inst/extdata/westerband_2022_wdate.csv diff --git a/data-raw/supported-terms.csv b/inst/supported-terms.csv similarity index 100% rename from data-raw/supported-terms.csv rename to inst/supported-terms.csv diff --git a/tests/mytests.R b/tests/mytests.R deleted file mode 100644 index db3589b..0000000 --- a/tests/mytests.R +++ /dev/null @@ -1,68 +0,0 @@ -library(tibble) -library(readr) -library(dplyr) -library(tidyr) -library(here) - -df <- read_csv(here("inst", "examples", "data", "westerband_2022_wdate.csv")) - -# take a small sample -df_filtered <- df |> - select(Site, Species, Latitude, Longitude, LMA_g.m2, LeafN_area_g.m2, PNUE) |> - slice(200:300) - -df_nested <- df_filtered |> - group_split(row_number(), .keep = FALSE) %>% - purrr::map_dfr( ~ .x |> - nest(measurementOrFact = c(LMA_g.m2, LeafN_area_g.m2, PNUE))) - # nest(measurementOrFact = c(LMA_g.m2, LeafN_area_g.m2, PNUE)) - -test_string <- c("g/m2", "g/m2", "who knows") -another_string <- c("leaf mass per area", "leaf Nitrogen per area", "PNUE") - -df_nested |> - dplyr::mutate( - measurementOrFact = purrr::map( - measurementOrFact, - ~ .x |> - pivot_longer(names_to = "column_name", - values_to = "measurementValue", - cols = everything()) |> - mutate( - measurementUnit = test_string, - measurementType = another_string - ) - )) |> - unnest(measurementOrFact) - - -very_nested <- df_nested |> - nest(data = c(Species, Latitude, Longitude, measurementOrFact)) - -very_nested - - -very_nested |> - unnest(data) - -df_filtered |> - slice(270:280) - -df_filtered - -test <- df_filtered |> - slice(200:300) |> - use_measurements(cols = c(LMA_g.m2, LeafN_area_g.m2, PNUE), - unit = c("g/m2", "g/m2", "something else"), - type = c("leaf mass per area", "leaf nitrogen per area", "gibberish")) - -test - -test |> - slice(1:3) |> - unnest(measurementOrFact) - - -number <- 7490 - -floor(log10(number)) + 1 diff --git a/tests/testthat/test-use_sf.R b/tests/testthat/test-use_sf.R index 72208f4..fe308d6 100644 --- a/tests/testthat/test-use_sf.R +++ b/tests/testthat/test-use_sf.R @@ -1,7 +1,7 @@ #--- # load small dataset of occurrence records -occs <- nanoparquet::read_parquet(here::here("tests", "testthat", "testdata", "bandicoots.parquet")) +occs <- nanoparquet::read_parquet("testdata/bandicoots.parquet") # set lat/lon to sf `geometry` occs_clean <- occs |> diff --git a/vignettes/checking-your-dataset.Rmd b/vignettes/checking-your-dataset.Rmd index 43ea626..2e0a402 100644 --- a/vignettes/checking-your-dataset.Rmd +++ b/vignettes/checking-your-dataset.Rmd @@ -56,7 +56,7 @@ corella contains internal `check_` functions for all individual Darwin Core term # generate table # fn_to_term_table() |> # dplyr::bind_rows() |> -# write.csv(here::here("data-raw", "supported-terms.csv")) +# write.csv("inst/supported-terms.csv") ``` @@ -67,7 +67,8 @@ corella contains internal `check_` functions for all individual Darwin Core term library(gt) library(dplyr) -readr::read_csv(here::here("data-raw", "supported-terms.csv")) |> +readr::read_csv(system.file("supported-terms.csv", + package = "corella")) |> select(-1) |> # remove reference column mutate( check_function = glue::glue("check_{dwc_term}()") diff --git a/vignettes/quick_start_guide.Rmd b/vignettes/quick_start_guide.Rmd index 79468d0..f8d2bbb 100644 --- a/vignettes/quick_start_guide.Rmd +++ b/vignettes/quick_start_guide.Rmd @@ -102,7 +102,6 @@ What happens when we add a column with an error in it? In our `df`, the `latitud ```{r} #| eval: true #| error: true -# is it possible to print this error? df |> use_scientific_name(scientificName = species) |> use_coordinates(decimalLongitude = longitude, @@ -207,10 +206,12 @@ library(tibble) library(readr) library(dplyr) library(tidyr) -library(here) # take a small sample -df_filtered <- read_csv(here("inst", "examples", "data", "westerband_2022_wdate.csv")) |> +df_filtered <- system.file("extdata", + "westerband_2022_wdate.csv", + package = "corella") |> + read_csv() |> select(Site, Species, Latitude, Longitude, LMA_g.m2, LeafN_area_g.m2, PNUE) df_filtered