From 329b848eb68806759d2b63303f6592d5fe0418f9 Mon Sep 17 00:00:00 2001 From: maurolepore Date: Thu, 6 Dec 2018 09:55:55 -0500 Subject: [PATCH 1/8] Export internal functions used in other fgeo packages. --- .buildignore/tmp.R | 30 ++-- NAMESPACE | 6 + R/check_crucial_names.R | 8 +- R/flag_if.R | 9 +- R/guess_plotdim.R | 5 +- R/name_dfs.R | 7 +- R/suffix_match.R | 7 +- docs/reference/add_status_tree.html | 4 +- docs/reference/add_var.html | 4 +- docs/reference/check_crucial_names.html | 187 +++++++++++++++++++++ docs/reference/fill_na.html | 2 +- docs/reference/flag_if.html | 213 ++++++++++++++++++++++++ docs/reference/flag_if_group.html | 10 +- docs/reference/guess_plotdim.html | 191 +++++++++++++++++++++ docs/reference/is_named.html | 181 ++++++++++++++++++++ docs/reference/lookup.html | 2 +- docs/reference/name_dfs.html | 208 +++++++++++++++++++++++ docs/reference/nms.html | 3 +- docs/reference/nms_extract_anycase.html | 3 +- docs/reference/nms_lowercase.html | 3 +- docs/reference/nms_restore_newvar.html | 3 +- docs/reference/nms_tidy.html | 3 +- docs/reference/nms_try_rename.html | 3 +- docs/reference/op-null-default.html | 173 +++++++++++++++++++ docs/reference/pick_drop.html | 5 +- docs/reference/suffix_match.html | 210 +++++++++++++++++++++++ docs/reference/to_tidy_names.html | 2 +- docs/sitemap.xml | 18 ++ man/add_status_tree.Rd | 4 +- man/add_var.Rd | 4 +- man/check_crucial_names.Rd | 39 +++++ man/fill_na.Rd | 2 +- man/flag_if.Rd | 60 +++++++ man/flag_if_group.Rd | 2 + man/guess_plotdim.Rd | 46 +++++ man/is_named.Rd | 36 ++++ man/lookup.Rd | 2 +- man/name_dfs.Rd | 37 ++++ man/nms.Rd | 3 +- man/nms_extract_anycase.Rd | 3 +- man/nms_lowercase.Rd | 3 +- man/nms_restore_newvar.Rd | 3 +- man/nms_tidy.Rd | 3 +- man/nms_try_rename.Rd | 3 +- man/pick_drop.Rd | 6 +- man/suffix_match.Rd | 56 +++++++ man/to_tidy_names.Rd | 2 +- 47 files changed, 1751 insertions(+), 63 deletions(-) create mode 100644 docs/reference/check_crucial_names.html create mode 100644 docs/reference/flag_if.html create mode 100644 docs/reference/guess_plotdim.html create mode 100644 docs/reference/is_named.html create mode 100644 docs/reference/name_dfs.html create mode 100644 docs/reference/op-null-default.html create mode 100644 docs/reference/suffix_match.html create mode 100644 man/check_crucial_names.Rd create mode 100644 man/flag_if.Rd create mode 100644 man/guess_plotdim.Rd create mode 100644 man/is_named.Rd create mode 100644 man/name_dfs.Rd create mode 100644 man/suffix_match.Rd diff --git a/.buildignore/tmp.R b/.buildignore/tmp.R index 9f813ba3..fcdb31f2 100644 --- a/.buildignore/tmp.R +++ b/.buildignore/tmp.R @@ -1,26 +1,26 @@ -operators.R -check_crucial_names.R -guess_plotdim.R -has_table_names.R -suffix_match.R -flag_if.R -collapse_censusid.R -name_dfs.R -rename_matches.R -warn_na.R -detect_if.R -to_tidy_names.R -gather_mat.R -drop_if_na.R -round_any.R +# TODO: +# Remove useless roxygen complexity? +#' @rdname flag_if +#' @keywords internal +#' @noRd +# https://github.com/forestgeo/fgeo.tool/issues/96 +# * Export functions that are used more than once +# check_crucial_names +# flag_if +# guess_plotdim +# name_dfs +# suffix_match +# * Move functions that are used exactly once. +all other +# Stuff ------------------------------------------------------------------- diff --git a/NAMESPACE b/NAMESPACE index ee43c76f..a713fdf2 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -30,6 +30,7 @@ export(add_subquad) export(arrange) export(as_censuses) export(as_tibble) +export(check_crucial_names) export(contains) export(convert_unit) export(convert_unit_at) @@ -57,15 +58,19 @@ export(fgeo_topography) export(fill_na) export(filter) export(filter_status) +export(flag_if) export(flag_if_group) export(group_by) +export(guess_plotdim) export(hide_data_of_class) +export(is_named) export(last_col) export(list_csv) export(list_df) export(lookup) export(matches) export(mutate) +export(name_dfs) export(nms_detect) export(nms_extract1) export(nms_extract_all) @@ -105,6 +110,7 @@ export(select) export(show_data_of_class) export(standardize_at) export(starts_with) +export(suffix_match) export(suffix_tags_beyond_edge) export(summarise) export(summarize) diff --git a/R/check_crucial_names.R b/R/check_crucial_names.R index a2cead8c..7fceef5f 100644 --- a/R/check_crucial_names.R +++ b/R/check_crucial_names.R @@ -9,8 +9,10 @@ #' #' #' @return Invisible `x`, or an error with informative message. +#' +#' @family exported functions for internal use +#' @export #' @keywords internal -#' @noRd #' #' @examples #' v <- c(x = 1) @@ -40,8 +42,10 @@ check_crucial_names <- function(x, nms) { #' @family general predicates #' #' @return The scalar `TRUE` or `FALSE`. +#' +#' @family functions for internal use in other fgeo packages #' @keywords internal -#' @noRd +#' @export #' #' @examples #' is_named(c(x = 1)) diff --git a/R/flag_if.R b/R/flag_if.R index 94c521c9..3526e7e1 100644 --- a/R/flag_if.R +++ b/R/flag_if.R @@ -12,12 +12,13 @@ #' @param msg String. An optional custom message. #' @param ... Other arguments passed to methods. #' -#' @family functions to throw conditions -#' #' @return A condition (and `.data` invisibly). +#' +#' @family functions to throw conditions +#' @family functions for internal use in other fgeo packages #' @keywords internal -#' @noRd -#' +#' @export +#' #' @examples #' # WITH VECTORS #' dupl <- c(1, 1) diff --git a/R/guess_plotdim.R b/R/guess_plotdim.R index 5bb180c9..0b639dbc 100644 --- a/R/guess_plotdim.R +++ b/R/guess_plotdim.R @@ -10,9 +10,10 @@ #' @family functions for fgeo census. #' @family functions for fgeo vft. #' @family general functions to find or approximate -#' +#' @family functions for internal use in other fgeo packages #' @keywords internal -#' @noRd +#' @export +#' #' @examples #' x <- data.frame( #' gx = c(0, 300, 979), diff --git a/R/name_dfs.R b/R/name_dfs.R index 6b9a93e9..b1973a7c 100644 --- a/R/name_dfs.R +++ b/R/name_dfs.R @@ -6,11 +6,12 @@ #' @param dfs A list of dataframes. #' @param name Names of the columns that store the names and values. #' -#' @family general functions to deal with names -#' #' @return A list of dataframes. +#' +#' @family general functions to deal with names +#' @family functions for internal use in other fgeo packages #' @keywords internal -#' @noRd +#' @export #' #' @examples #' dfs <- list(a = data.frame(x = 1), b = data.frame(x = 1)) diff --git a/R/suffix_match.R b/R/suffix_match.R index f382a83b..d252dcf7 100644 --- a/R/suffix_match.R +++ b/R/suffix_match.R @@ -5,11 +5,12 @@ #' @param .match A string to match the vector `to_match` with. #' @param suffix A suffix to add at the end of each element of `string`. #' -#' @family general functions to edit data in place -#' #' @return A modified version of `x`. +#' +#' @family general functions to edit data in place +#' @family functions for internal use in other fgeo packages #' @keywords internal -#' @noRd +#' @export #' #' @examples #' suffix_match( diff --git a/docs/reference/add_status_tree.html b/docs/reference/add_status_tree.html index f0a72534..ea18793f 100644 --- a/docs/reference/add_status_tree.html +++ b/docs/reference/add_status_tree.html @@ -147,9 +147,9 @@

See a

Other functions for ForestGEO data.: add_subquad, add_var

Other functions for fgeo census.: add_var, - pick_drop

+ guess_plotdim, pick_drop

Other functions for fgeo vft.: add_var, - pick_drop

+ guess_plotdim, pick_drop

Examples

diff --git a/docs/reference/add_var.html b/docs/reference/add_var.html index 341479dc..47d3d8d5 100644 --- a/docs/reference/add_var.html +++ b/docs/reference/add_var.html @@ -179,9 +179,9 @@

See a

Other functions for ForestGEO data.: add_status_tree, add_subquad

Other functions for fgeo census.: add_status_tree, - pick_drop

+ guess_plotdim, pick_drop

Other functions for fgeo vft.: add_status_tree, - pick_drop

+ guess_plotdim, pick_drop

Examples

diff --git a/docs/reference/check_crucial_names.html b/docs/reference/check_crucial_names.html new file mode 100644 index 00000000..324b4882 --- /dev/null +++ b/docs/reference/check_crucial_names.html @@ -0,0 +1,187 @@ + + + + + + + + +Check if an object contains specific names. — check_crucial_names • fgeo.tool + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + +
+ +

Check if an object contains specific names.

+ +
+ +
check_crucial_names(x, nms)
+ +

Arguments

+ + + + + + + + + + +
x

A named object.

nms

String; names expected to be found in x.

+ +

Value

+ +

Invisible x, or an error with informative message.

+ +

See also

+ +

Other functions to check inputs.: flag_if_group

+

Other functions for developers: nms_extract_anycase, + nms_lowercase, + nms_restore_newvar, nms_tidy, + nms_try_rename, nms

+ + +

Examples

+
v <- c(x = 1) +check_crucial_names(v, "x") + +dfm <- data.frame(x = 1) +check_crucial_names(dfm, "x")
+
+ +
+ + +
+ + + + + + diff --git a/docs/reference/fill_na.html b/docs/reference/fill_na.html index 83a91846..5c59fbd2 100644 --- a/docs/reference/fill_na.html +++ b/docs/reference/fill_na.html @@ -145,7 +145,7 @@

Value

See also

Other general functions to edit data in place: lookup, - to_tidy_names

+ suffix_match, to_tidy_names

Examples

diff --git a/docs/reference/flag_if.html b/docs/reference/flag_if.html new file mode 100644 index 00000000..2c0429fe --- /dev/null +++ b/docs/reference/flag_if.html @@ -0,0 +1,213 @@ + + + + + + + + +Flag if a vector or dataframe-column meets a condition. — flag_if • fgeo.tool + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + +
+ +

This function returns a condition (error, warning, or message) and its first +argument, invisibly. It is a generic. If the first input is a vector, it +evaluates it directly; if it is is a dataframe, it evaluates a given column.

+ +
+ +
flag_if(.data, ...)
+ +

Arguments

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
.data

Vector.

...

Other arguments passed to methods.

name

String. The name of a column of a dataframe.

predicate

A predicate function.

condition

A condition function (e.g. stop(), warning(), +rlang::inform()).

msg

String. An optional custom message.

+ +

Value

+ +

A condition (and .data invisibly).

+ +

See also

+ +

Other functions for internal use in other fgeo packages: guess_plotdim, + is_named, name_dfs, + suffix_match

+ + +

Examples

+
# WITH VECTORS +dupl <- c(1, 1) +flag_if(dupl, is_duplicated)
#> Error in UseMethod("flag_if"): no applicable method for 'flag_if' applied to an object of class "c('double', 'numeric')"
# Silent +flag_if(dupl, is_multiple)
#> Error in UseMethod("flag_if"): no applicable method for 'flag_if' applied to an object of class "c('double', 'numeric')"
+mult <- c(1, 2) +flag_if(mult, is_multiple, message, "Custom")
#> Error in UseMethod("flag_if"): no applicable method for 'flag_if' applied to an object of class "c('double', 'numeric')"
# Silent +flag_if(mult, is_duplicated)
#> Error in UseMethod("flag_if"): no applicable method for 'flag_if' applied to an object of class "c('double', 'numeric')"
+# Both silent +flag_if(c(1, NA), is_multiple)
#> Error in UseMethod("flag_if"): no applicable method for 'flag_if' applied to an object of class "c('double', 'numeric')"
flag_if(c(1, NA), is_duplicated)
#> Error in UseMethod("flag_if"): no applicable method for 'flag_if' applied to an object of class "c('double', 'numeric')"
+# WITH DATAFRAMES +.df <- data.frame(a = 1:3, b = 1, stringsAsFactors = FALSE) +flag_if(.df, "b", is_multiple)
#> Error in UseMethod("flag_if"): no applicable method for 'flag_if' applied to an object of class "data.frame"
flag_if(.df, "a", is_multiple)
#> Error in UseMethod("flag_if"): no applicable method for 'flag_if' applied to an object of class "data.frame"
flag_if(.df, "a", is_multiple, message, "Custom")
#> Error in UseMethod("flag_if"): no applicable method for 'flag_if' applied to an object of class "data.frame"
+
+ +
+ + +
+ + + + + + diff --git a/docs/reference/flag_if_group.html b/docs/reference/flag_if_group.html index c59870ef..8c26b2ff 100644 --- a/docs/reference/flag_if_group.html +++ b/docs/reference/flag_if_group.html @@ -116,7 +116,7 @@

Detect and flag based on a predicate applied to a variable by groups.

-

These functions extend flag_if() and detect_if() to +

These functions extend flag_if() and detect_if() to work by groups defined with dplyr::group_by().

@@ -162,7 +162,8 @@

Value

See also

-

Other functions for developers.: find_data_of_class, +

Other functions to check inputs.: check_crucial_names

+

Other functions for developers.: find_data_of_class, type_ensure

@@ -170,8 +171,9 @@

Examp
library(fgeo.base)
#> #> Attaching package: 'fgeo.base'
#> The following objects are masked from 'package:fgeo.tool': #> -#> drop_status, fill_na, pick_dbh_max, pick_dbh_min, pick_dbh_over, -#> pick_dbh_under, pick_status, to_tidy_names
+#> check_crucial_names, drop_status, fill_na, flag_if, guess_plotdim, +#> is_named, name_dfs, pick_dbh_max, pick_dbh_min, pick_dbh_over, +#> pick_dbh_under, pick_status, suffix_match, to_tidy_names
tree <- tibble(CensusID = c(1, 2), treeID = c(1, 2)) detect_if_group(tree, "treeID", is_multiple)
#> [1] TRUE
flag_if_group(tree, "treeID", is_multiple)
#> Warning: treeID: Flagged values were detected.
by_censusid <- group_by(tree, CensusID) diff --git a/docs/reference/guess_plotdim.html b/docs/reference/guess_plotdim.html new file mode 100644 index 00000000..85e48c28 --- /dev/null +++ b/docs/reference/guess_plotdim.html @@ -0,0 +1,191 @@ + + + + + + + + +Guess plot dimensions. — guess_plotdim • fgeo.tool + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + +
+ +

Guess plot dimensions.

+ +
+ +
guess_plotdim(x, accuracy = 20)
+ +

Arguments

+ + + + + + + + + + +
x

A dataframe; a ForestGEO dataset (census or ViewFullTable).

accuracy

A number giving the accuracy with which to round gx and +gy.

+ +

Value

+ +

A numeric vector of length 2.

+ +

See also

+ +

Other functions for fgeo census and vft.: pick_drop

+

Other functions for fgeo census.: add_status_tree, + add_var, pick_drop

+

Other functions for fgeo vft.: add_status_tree, + add_var, pick_drop

+

Other functions for internal use in other fgeo packages: flag_if, + is_named, name_dfs, + suffix_match

+ + +

Examples

+
x <- data.frame( + gx = c(0, 300, 979), + gy = c(0, 300, 481) +) +guess_plotdim(x)
#> Guessing: plotdim = c(980, 500)
#> [1] 980 500
+
+ +
+ + +
+ + + + + + diff --git a/docs/reference/is_named.html b/docs/reference/is_named.html new file mode 100644 index 00000000..ceeefdf3 --- /dev/null +++ b/docs/reference/is_named.html @@ -0,0 +1,181 @@ + + + + + + + + +Is named object? (Base-only version of rlang::is_named). — is_named • fgeo.tool + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + +
+ +

Is named object? (Base-only version of rlang::is_named).

+ +
+ +
is_named(x)
+ +

Arguments

+ + + + + + +
x

An object to test.

+ +

Value

+ +

The scalar TRUE or FALSE.

+ +

See also

+ +

Other functions for internal use in other fgeo packages: flag_if, + guess_plotdim, name_dfs, + suffix_match

+ + +

Examples

+
is_named(c(x = 1))
#> [1] TRUE
is_named(c(1))
#> [1] FALSE
is_named(x = 1)
#> [1] FALSE
+is_named(data.frame(x = 1))
#> [1] TRUE
+dfm <- data.frame(1) +is_named(dfm)
#> [1] TRUE
dfm
#> X1 +#> 1 1
+
+ +
+ + +
+ + + + + + diff --git a/docs/reference/lookup.html b/docs/reference/lookup.html index 5419a13c..bf3aa447 100644 --- a/docs/reference/lookup.html +++ b/docs/reference/lookup.html @@ -150,7 +150,7 @@

See a

dplyr::recode()

Other general functions to edit data in place: fill_na, - to_tidy_names

+ suffix_match, to_tidy_names

Examples

diff --git a/docs/reference/name_dfs.html b/docs/reference/name_dfs.html new file mode 100644 index 00000000..9e92b1f2 --- /dev/null +++ b/docs/reference/name_dfs.html @@ -0,0 +1,208 @@ + + + + + + + + +Identify each dataframe in a list with a name. — name_dfs • fgeo.tool + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + +
+ +

Identify each dataframe in a list with the name of the corresponding list +item.

+ +
+ +
name_dfs(dfs, name = "name")
+ +

Arguments

+ + + + + + + + + + +
dfs

A list of dataframes.

name

Names of the columns that store the names and values.

+ +

Value

+ +

A list of dataframes.

+ +

See also

+ +

Other functions for internal use in other fgeo packages: flag_if, + guess_plotdim, is_named, + suffix_match

+ + +

Examples

+
dfs <- list(a = data.frame(x = 1), b = data.frame(x = 1)) +name_dfs(dfs)
#> $a +#> x name +#> 1 1 a +#> +#> $b +#> x name +#> 1 1 b +#>
+name_dfs(dfs, "custom_name")
#> $a +#> x custom_name +#> 1 1 a +#> +#> $b +#> x custom_name +#> 1 1 b +#>
+dfs2 <- list(data.frame(x = 1), data.frame(x = 1)) +name_dfs(dfs2)
#> $df1 +#> x name +#> 1 1 df1 +#> +#> $df2 +#> x name +#> 1 1 df2 +#>
+
+ +
+ + +
+ + + + + + diff --git a/docs/reference/nms.html b/docs/reference/nms.html index f5301ea1..be4ef915 100644 --- a/docs/reference/nms.html +++ b/docs/reference/nms.html @@ -160,7 +160,8 @@

Details

See also

-

Other functions for developers: nms_extract_anycase, +

Other functions for developers: check_crucial_names, + nms_extract_anycase, nms_lowercase, nms_restore_newvar, nms_tidy, nms_try_rename

diff --git a/docs/reference/nms_extract_anycase.html b/docs/reference/nms_extract_anycase.html index bfd26190..cda1e4fd 100644 --- a/docs/reference/nms_extract_anycase.html +++ b/docs/reference/nms_extract_anycase.html @@ -140,7 +140,8 @@

Value

See also

-

Other functions for developers: nms_lowercase, +

Other functions for developers: check_crucial_names, + nms_lowercase, nms_restore_newvar, nms_tidy, nms_try_rename, nms

Other functions dealing with names: nms_lowercase, diff --git a/docs/reference/nms_lowercase.html b/docs/reference/nms_lowercase.html index 4dbfbe55..f8df4ed8 100644 --- a/docs/reference/nms_lowercase.html +++ b/docs/reference/nms_lowercase.html @@ -159,7 +159,8 @@

See a

Other functions dealing with names: nms_extract_anycase, nms_restore_newvar, nms_tidy, nms_try_rename, nms

-

Other functions for developers: nms_extract_anycase, +

Other functions for developers: check_crucial_names, + nms_extract_anycase, nms_restore_newvar, nms_tidy, nms_try_rename, nms

diff --git a/docs/reference/nms_restore_newvar.html b/docs/reference/nms_restore_newvar.html index 73cd00ab..d27e0a3d 100644 --- a/docs/reference/nms_restore_newvar.html +++ b/docs/reference/nms_restore_newvar.html @@ -170,7 +170,8 @@

See a

Other functions dealing with names: nms_extract_anycase, nms_lowercase, nms_tidy, nms_try_rename, nms

-

Other functions for developers: nms_extract_anycase, +

Other functions for developers: check_crucial_names, + nms_extract_anycase, nms_lowercase, nms_tidy, nms_try_rename, nms

diff --git a/docs/reference/nms_tidy.html b/docs/reference/nms_tidy.html index d72ab307..1d7d258e 100644 --- a/docs/reference/nms_tidy.html +++ b/docs/reference/nms_tidy.html @@ -146,7 +146,8 @@

See a nms_lowercase, nms_restore_newvar, nms_try_rename, nms

-

Other functions for developers: nms_extract_anycase, +

Other functions for developers: check_crucial_names, + nms_extract_anycase, nms_lowercase, nms_restore_newvar, nms_try_rename, nms

diff --git a/docs/reference/nms_try_rename.html b/docs/reference/nms_try_rename.html index 50b0e7fa..1b0a7635 100644 --- a/docs/reference/nms_try_rename.html +++ b/docs/reference/nms_try_rename.html @@ -147,7 +147,8 @@

See a nms_lowercase, nms_restore_newvar, nms_tidy, nms

-

Other functions for developers: nms_extract_anycase, +

Other functions for developers: check_crucial_names, + nms_extract_anycase, nms_lowercase, nms_restore_newvar, nms_tidy, nms

diff --git a/docs/reference/op-null-default.html b/docs/reference/op-null-default.html new file mode 100644 index 00000000..bb2cd1aa --- /dev/null +++ b/docs/reference/op-null-default.html @@ -0,0 +1,173 @@ + + + + + + + + +Default value for <code>NULL</code>. — op-null-default • fgeo.tool + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + +
+ +

This infix function makes it easy to replace NULLs with a default value. +It's inspired by the way that Ruby's or operation (||) works. It is slightly +adapted from rlang::

+ +
+ +
x %||% y
+ +

Arguments

+ + + + + + +
x, y

If x is NULL, will return y; otherwise returns x.

+ +

See also

+ +

Other functions for internal use in other fgeo packages: guess_plotdim

+ + +

Examples

+
1 %||% 2
#> [1] 1
NULL %||% 2
#> [1] 2
+
+ +
+ + +
+ + + + + + diff --git a/docs/reference/pick_drop.html b/docs/reference/pick_drop.html index 73aaac5d..1c0eb2d4 100644 --- a/docs/reference/pick_drop.html +++ b/docs/reference/pick_drop.html @@ -167,10 +167,11 @@

Value

See also

dplyr::filter(), Extract ([).

+

Other functions for fgeo census and vft.: guess_plotdim

Other functions for fgeo census.: add_status_tree, - add_var

+ add_var, guess_plotdim

Other functions for fgeo vft.: add_status_tree, - add_var

+ add_var, guess_plotdim

Other functions to pick or drop rows of a ForestGEO dataframe: drop_twice_dead, filter_status, pick_main_stem, pick

diff --git a/docs/reference/suffix_match.html b/docs/reference/suffix_match.html new file mode 100644 index 00000000..55b958f5 --- /dev/null +++ b/docs/reference/suffix_match.html @@ -0,0 +1,210 @@ + + + + + + + + +Suffix a strings where a vector exactly matches one specific string. — suffix_match • fgeo.tool + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + +
+ +

Suffix a strings where a vector exactly matches one specific string.

+ +
+ +
suffix_match(string, to_match, .match, suffix)
+ +

Arguments

+ + + + + + + + + + + + + + + + + + +
string

A vector of strings to suffix.

to_match

A vector of strings to match with .match.

.match

A string to match the vector to_match with.

suffix

A suffix to add at the end of each element of string.

+ +

Value

+ +

A modified version of x.

+ +

See also

+ +

Other general functions to edit data in place: fill_na, + lookup, to_tidy_names

+

Other functions for internal use in other fgeo packages: flag_if, + guess_plotdim, is_named, + name_dfs

+ + +

Examples

+
suffix_match( + string = c("one", "banana"), + to_match = c("number", "fruit"), + .match = "number", + suffix = "_num" +)
#> [1] "one_num" "banana"
+suffix_match( + string = c("tag1", "tag2"), + to_match = c("dead", "not-dead"), + .match = "dead", + suffix = ".d" +)
#> [1] "tag1.d" "tag2"
+vft <- data.frame( + Tag = c("01", "02"), + Status = c("dead", "alive"), + stringsAsFactors = FALSE +) +transform(vft, tagged = suffix_match(Tag, Status, "dead", ".d"))
#> Tag Status tagged +#> 1 01 dead 01.d +#> 2 02 alive 02
+
+ +
+ + +
+ + + + + + diff --git a/docs/reference/to_tidy_names.html b/docs/reference/to_tidy_names.html index a91f5ac5..8e7d9619 100644 --- a/docs/reference/to_tidy_names.html +++ b/docs/reference/to_tidy_names.html @@ -138,7 +138,7 @@

See a

fgeo.tool::nms_tidy().

Other general functions to edit data in place: fill_na, - lookup

+ lookup, suffix_match

Examples

diff --git a/docs/sitemap.xml b/docs/sitemap.xml index 7ae45ee9..2ff46a17 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -18,6 +18,9 @@ https://forestgeo.github.io/fgeo.tool//reference/as_censuses.html + + https://forestgeo.github.io/fgeo.tool//reference/check_crucial_names.html + https://forestgeo.github.io/fgeo.tool//reference/convert_unit.html @@ -51,9 +54,18 @@ https://forestgeo.github.io/fgeo.tool//reference/find_data_of_class.html + + https://forestgeo.github.io/fgeo.tool//reference/flag_if.html + https://forestgeo.github.io/fgeo.tool//reference/flag_if_group.html + + https://forestgeo.github.io/fgeo.tool//reference/guess_plotdim.html + + + https://forestgeo.github.io/fgeo.tool//reference/is_named.html + https://forestgeo.github.io/fgeo.tool//reference/list_csv.html @@ -63,6 +75,9 @@ https://forestgeo.github.io/fgeo.tool//reference/lookup.html + + https://forestgeo.github.io/fgeo.tool//reference/name_dfs.html + https://forestgeo.github.io/fgeo.tool//reference/nms.html @@ -123,6 +138,9 @@ https://forestgeo.github.io/fgeo.tool//reference/standardize_at.html + + https://forestgeo.github.io/fgeo.tool//reference/suffix_match.html + https://forestgeo.github.io/fgeo.tool//reference/suffix_tags_beyond_edge.html diff --git a/man/add_status_tree.Rd b/man/add_status_tree.Rd index 012d16e9..dc0c75ae 100644 --- a/man/add_status_tree.Rd +++ b/man/add_status_tree.Rd @@ -46,10 +46,10 @@ Other functions for ForestGEO data.: \code{\link{add_subquad}}, \code{\link{add_var}} Other functions for fgeo census.: \code{\link{add_var}}, - \code{\link{pick_drop}} + \code{\link{guess_plotdim}}, \code{\link{pick_drop}} Other functions for fgeo vft.: \code{\link{add_var}}, - \code{\link{pick_drop}} + \code{\link{guess_plotdim}}, \code{\link{pick_drop}} } \concept{functions for ForestGEO data.} \concept{functions for fgeo census.} diff --git a/man/add_var.Rd b/man/add_var.Rd index 5f064565..ba03fae8 100644 --- a/man/add_var.Rd +++ b/man/add_var.Rd @@ -84,10 +84,10 @@ Other functions for ForestGEO data.: \code{\link{add_status_tree}}, \code{\link{add_subquad}} Other functions for fgeo census.: \code{\link{add_status_tree}}, - \code{\link{pick_drop}} + \code{\link{guess_plotdim}}, \code{\link{pick_drop}} Other functions for fgeo vft.: \code{\link{add_status_tree}}, - \code{\link{pick_drop}} + \code{\link{guess_plotdim}}, \code{\link{pick_drop}} } \concept{functions for ForestGEO data.} \concept{functions for fgeo census.} diff --git a/man/check_crucial_names.Rd b/man/check_crucial_names.Rd new file mode 100644 index 00000000..564a48d0 --- /dev/null +++ b/man/check_crucial_names.Rd @@ -0,0 +1,39 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/check_crucial_names.R +\name{check_crucial_names} +\alias{check_crucial_names} +\title{Check if an object contains specific names.} +\usage{ +check_crucial_names(x, nms) +} +\arguments{ +\item{x}{A named object.} + +\item{nms}{String; names expected to be found in \code{x}.} +} +\value{ +Invisible \code{x}, or an error with informative message. +} +\description{ +Check if an object contains specific names. +} +\examples{ +v <- c(x = 1) +check_crucial_names(v, "x") + +dfm <- data.frame(x = 1) +check_crucial_names(dfm, "x") +} +\seealso{ +Other functions to check inputs.: \code{\link{flag_if_group}} + +Other functions for developers: \code{\link{nms_extract_anycase}}, + \code{\link{nms_lowercase}}, + \code{\link{nms_restore_newvar}}, \code{\link{nms_tidy}}, + \code{\link{nms_try_rename}}, \code{\link{nms}} +} +\concept{exported functions for internal use} +\concept{functions for developers} +\concept{functions to check inputs.} +\concept{general functions to assert} +\keyword{internal} diff --git a/man/fill_na.Rd b/man/fill_na.Rd index 64c17db1..08093cca 100644 --- a/man/fill_na.Rd +++ b/man/fill_na.Rd @@ -38,6 +38,6 @@ lapply(a_list, fill_na) } \seealso{ Other general functions to edit data in place: \code{\link{lookup}}, - \code{\link{to_tidy_names}} + \code{\link{suffix_match}}, \code{\link{to_tidy_names}} } \concept{general functions to edit data in place} diff --git a/man/flag_if.Rd b/man/flag_if.Rd new file mode 100644 index 00000000..59f16517 --- /dev/null +++ b/man/flag_if.Rd @@ -0,0 +1,60 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/flag_if.R +\name{flag_if} +\alias{flag_if} +\title{Flag if a vector or dataframe-column meets a condition.} +\usage{ +flag_if(.data, ...) +} +\arguments{ +\item{.data}{Vector.} + +\item{...}{Other arguments passed to methods.} + +\item{name}{String. The name of a column of a dataframe.} + +\item{predicate}{A predicate function.} + +\item{condition}{A condition function (e.g. \code{\link[=stop]{stop()}}, \code{\link[=warning]{warning()}}, +\code{rlang::inform()}).} + +\item{msg}{String. An optional custom message.} +} +\value{ +A condition (and \code{.data} invisibly). +} +\description{ +This function returns a condition (error, warning, or message) and its first +argument, invisibly. It is a generic. If the first input is a vector, it +evaluates it directly; if it is is a dataframe, it evaluates a given column. +} +\examples{ +# WITH VECTORS +dupl <- c(1, 1) +flag_if(dupl, is_duplicated) +# Silent +flag_if(dupl, is_multiple) + +mult <- c(1, 2) +flag_if(mult, is_multiple, message, "Custom") +# Silent +flag_if(mult, is_duplicated) + +# Both silent +flag_if(c(1, NA), is_multiple) +flag_if(c(1, NA), is_duplicated) + +# WITH DATAFRAMES +.df <- data.frame(a = 1:3, b = 1, stringsAsFactors = FALSE) +flag_if(.df, "b", is_multiple) +flag_if(.df, "a", is_multiple) +flag_if(.df, "a", is_multiple, message, "Custom") +} +\seealso{ +Other functions for internal use in other fgeo packages: \code{\link{guess_plotdim}}, + \code{\link{is_named}}, \code{\link{name_dfs}}, + \code{\link{suffix_match}} +} +\concept{functions for internal use in other fgeo packages} +\concept{functions to throw conditions} +\keyword{internal} diff --git a/man/flag_if_group.Rd b/man/flag_if_group.Rd index 1dd21883..8bc54235 100644 --- a/man/flag_if_group.Rd +++ b/man/flag_if_group.Rd @@ -43,6 +43,8 @@ detect_if_group(by_censusid, "treeID", is_multiple) flag_if_group(by_censusid, "treeID", is_multiple) } \seealso{ +Other functions to check inputs.: \code{\link{check_crucial_names}} + Other functions for developers.: \code{\link{find_data_of_class}}, \code{\link{type_ensure}} } diff --git a/man/guess_plotdim.Rd b/man/guess_plotdim.Rd new file mode 100644 index 00000000..007f1cc7 --- /dev/null +++ b/man/guess_plotdim.Rd @@ -0,0 +1,46 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/guess_plotdim.R +\name{guess_plotdim} +\alias{guess_plotdim} +\title{Guess plot dimensions.} +\usage{ +guess_plotdim(x, accuracy = 20) +} +\arguments{ +\item{x}{A dataframe; a ForestGEO dataset (census or ViewFullTable).} + +\item{accuracy}{A number giving the accuracy with which to round \code{gx} and +\code{gy}.} +} +\value{ +A numeric vector of length 2. +} +\description{ +Guess plot dimensions. +} +\examples{ +x <- data.frame( + gx = c(0, 300, 979), + gy = c(0, 300, 481) +) +guess_plotdim(x) +} +\seealso{ +Other functions for fgeo census and vft.: \code{\link{pick_drop}} + +Other functions for fgeo census.: \code{\link{add_status_tree}}, + \code{\link{add_var}}, \code{\link{pick_drop}} + +Other functions for fgeo vft.: \code{\link{add_status_tree}}, + \code{\link{add_var}}, \code{\link{pick_drop}} + +Other functions for internal use in other fgeo packages: \code{\link{flag_if}}, + \code{\link{is_named}}, \code{\link{name_dfs}}, + \code{\link{suffix_match}} +} +\concept{functions for fgeo census and vft.} +\concept{functions for fgeo census.} +\concept{functions for fgeo vft.} +\concept{functions for internal use in other fgeo packages} +\concept{general functions to find or approximate} +\keyword{internal} diff --git a/man/is_named.Rd b/man/is_named.Rd new file mode 100644 index 00000000..659d80e1 --- /dev/null +++ b/man/is_named.Rd @@ -0,0 +1,36 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/check_crucial_names.R +\name{is_named} +\alias{is_named} +\title{Is named object? (Base-only version of rlang::is_named).} +\usage{ +is_named(x) +} +\arguments{ +\item{x}{An object to test.} +} +\value{ +The scalar \code{TRUE} or \code{FALSE}. +} +\description{ +Is named object? (Base-only version of rlang::is_named). +} +\examples{ +is_named(c(x = 1)) +is_named(c(1)) +is_named(x = 1) + +is_named(data.frame(x = 1)) + +dfm <- data.frame(1) +is_named(dfm) +dfm +} +\seealso{ +Other functions for internal use in other fgeo packages: \code{\link{flag_if}}, + \code{\link{guess_plotdim}}, \code{\link{name_dfs}}, + \code{\link{suffix_match}} +} +\concept{functions for internal use in other fgeo packages} +\concept{general predicates} +\keyword{internal} diff --git a/man/lookup.Rd b/man/lookup.Rd index 19bda9ae..6d31613a 100644 --- a/man/lookup.Rd +++ b/man/lookup.Rd @@ -45,6 +45,6 @@ mutate(census, sp = recode(sp, lookup(look$old, look$new))) \code{dplyr::recode()} Other general functions to edit data in place: \code{\link{fill_na}}, - \code{\link{to_tidy_names}} + \code{\link{suffix_match}}, \code{\link{to_tidy_names}} } \concept{general functions to edit data in place} diff --git a/man/name_dfs.Rd b/man/name_dfs.Rd new file mode 100644 index 00000000..3672418f --- /dev/null +++ b/man/name_dfs.Rd @@ -0,0 +1,37 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/name_dfs.R +\name{name_dfs} +\alias{name_dfs} +\title{Identify each dataframe in a list with a name.} +\usage{ +name_dfs(dfs, name = "name") +} +\arguments{ +\item{dfs}{A list of dataframes.} + +\item{name}{Names of the columns that store the names and values.} +} +\value{ +A list of dataframes. +} +\description{ +Identify each dataframe in a list with the name of the corresponding list +item. +} +\examples{ +dfs <- list(a = data.frame(x = 1), b = data.frame(x = 1)) +name_dfs(dfs) + +name_dfs(dfs, "custom_name") + +dfs2 <- list(data.frame(x = 1), data.frame(x = 1)) +name_dfs(dfs2) +} +\seealso{ +Other functions for internal use in other fgeo packages: \code{\link{flag_if}}, + \code{\link{guess_plotdim}}, \code{\link{is_named}}, + \code{\link{suffix_match}} +} +\concept{functions for internal use in other fgeo packages} +\concept{general functions to deal with names} +\keyword{internal} diff --git a/man/nms.Rd b/man/nms.Rd index fff7d187..a7e02d44 100644 --- a/man/nms.Rd +++ b/man/nms.Rd @@ -61,7 +61,8 @@ stem <- fgeo.x::stem6 nms_extract_all(stem, "gx", "gy", "PX", "PY") } \seealso{ -Other functions for developers: \code{\link{nms_extract_anycase}}, +Other functions for developers: \code{\link{check_crucial_names}}, + \code{\link{nms_extract_anycase}}, \code{\link{nms_lowercase}}, \code{\link{nms_restore_newvar}}, \code{\link{nms_tidy}}, \code{\link{nms_try_rename}} diff --git a/man/nms_extract_anycase.Rd b/man/nms_extract_anycase.Rd index 87e12f11..0ad31622 100644 --- a/man/nms_extract_anycase.Rd +++ b/man/nms_extract_anycase.Rd @@ -25,7 +25,8 @@ dfm <- data.frame(a = 1, B = 1) nms_extract_anycase(dfm, "b") } \seealso{ -Other functions for developers: \code{\link{nms_lowercase}}, +Other functions for developers: \code{\link{check_crucial_names}}, + \code{\link{nms_lowercase}}, \code{\link{nms_restore_newvar}}, \code{\link{nms_tidy}}, \code{\link{nms_try_rename}}, \code{\link{nms}} diff --git a/man/nms_lowercase.Rd b/man/nms_lowercase.Rd index 7893a19b..f7a33852 100644 --- a/man/nms_lowercase.Rd +++ b/man/nms_lowercase.Rd @@ -49,7 +49,8 @@ Other functions dealing with names: \code{\link{nms_extract_anycase}}, \code{\link{nms_restore_newvar}}, \code{\link{nms_tidy}}, \code{\link{nms_try_rename}}, \code{\link{nms}} -Other functions for developers: \code{\link{nms_extract_anycase}}, +Other functions for developers: \code{\link{check_crucial_names}}, + \code{\link{nms_extract_anycase}}, \code{\link{nms_restore_newvar}}, \code{\link{nms_tidy}}, \code{\link{nms_try_rename}}, \code{\link{nms}} } diff --git a/man/nms_restore_newvar.Rd b/man/nms_restore_newvar.Rd index a73c5448..9ed03178 100644 --- a/man/nms_restore_newvar.Rd +++ b/man/nms_restore_newvar.Rd @@ -61,7 +61,8 @@ Other functions dealing with names: \code{\link{nms_extract_anycase}}, \code{\link{nms_lowercase}}, \code{\link{nms_tidy}}, \code{\link{nms_try_rename}}, \code{\link{nms}} -Other functions for developers: \code{\link{nms_extract_anycase}}, +Other functions for developers: \code{\link{check_crucial_names}}, + \code{\link{nms_extract_anycase}}, \code{\link{nms_lowercase}}, \code{\link{nms_tidy}}, \code{\link{nms_try_rename}}, \code{\link{nms}} } diff --git a/man/nms_tidy.Rd b/man/nms_tidy.Rd index 2ad7050a..dc191f25 100644 --- a/man/nms_tidy.Rd +++ b/man/nms_tidy.Rd @@ -53,7 +53,8 @@ Other functions dealing with names: \code{\link{nms_extract_anycase}}, \code{\link{nms_restore_newvar}}, \code{\link{nms_try_rename}}, \code{\link{nms}} -Other functions for developers: \code{\link{nms_extract_anycase}}, +Other functions for developers: \code{\link{check_crucial_names}}, + \code{\link{nms_extract_anycase}}, \code{\link{nms_lowercase}}, \code{\link{nms_restore_newvar}}, \code{\link{nms_try_rename}}, \code{\link{nms}} diff --git a/man/nms_try_rename.Rd b/man/nms_try_rename.Rd index b99797a3..1d58fa12 100644 --- a/man/nms_try_rename.Rd +++ b/man/nms_try_rename.Rd @@ -36,7 +36,8 @@ Other functions dealing with names: \code{\link{nms_extract_anycase}}, \code{\link{nms_restore_newvar}}, \code{\link{nms_tidy}}, \code{\link{nms}} -Other functions for developers: \code{\link{nms_extract_anycase}}, +Other functions for developers: \code{\link{check_crucial_names}}, + \code{\link{nms_extract_anycase}}, \code{\link{nms_lowercase}}, \code{\link{nms_restore_newvar}}, \code{\link{nms_tidy}}, \code{\link{nms}} diff --git a/man/pick_drop.Rd b/man/pick_drop.Rd index 6258c840..ce260e29 100644 --- a/man/pick_drop.Rd +++ b/man/pick_drop.Rd @@ -78,11 +78,13 @@ pick_dbh_over(drop_status(cns, "D", na.rm = TRUE), 100) \seealso{ \code{dplyr::filter()}, \code{Extract} (\code{[}). +Other functions for fgeo census and vft.: \code{\link{guess_plotdim}} + Other functions for fgeo census.: \code{\link{add_status_tree}}, - \code{\link{add_var}} + \code{\link{add_var}}, \code{\link{guess_plotdim}} Other functions for fgeo vft.: \code{\link{add_status_tree}}, - \code{\link{add_var}} + \code{\link{add_var}}, \code{\link{guess_plotdim}} Other functions to pick or drop rows of a ForestGEO dataframe: \code{\link{drop_twice_dead}}, \code{\link{filter_status}}, diff --git a/man/suffix_match.Rd b/man/suffix_match.Rd new file mode 100644 index 00000000..c750fcf7 --- /dev/null +++ b/man/suffix_match.Rd @@ -0,0 +1,56 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/suffix_match.R +\name{suffix_match} +\alias{suffix_match} +\title{Suffix a strings where a vector exactly matches one specific string.} +\usage{ +suffix_match(string, to_match, .match, suffix) +} +\arguments{ +\item{string}{A vector of strings to suffix.} + +\item{to_match}{A vector of strings to match with \code{.match}.} + +\item{.match}{A string to match the vector \code{to_match} with.} + +\item{suffix}{A suffix to add at the end of each element of \code{string}.} +} +\value{ +A modified version of \code{x}. +} +\description{ +Suffix a strings where a vector exactly matches one specific string. +} +\examples{ +suffix_match( + string = c("one", "banana"), + to_match = c("number", "fruit"), + .match = "number", + suffix = "_num" +) + +suffix_match( + string = c("tag1", "tag2"), + to_match = c("dead", "not-dead"), + .match = "dead", + suffix = ".d" +) + +vft <- data.frame( + Tag = c("01", "02"), + Status = c("dead", "alive"), + stringsAsFactors = FALSE +) +transform(vft, tagged = suffix_match(Tag, Status, "dead", ".d")) +} +\seealso{ +Other general functions to edit data in place: \code{\link{fill_na}}, + \code{\link{lookup}}, \code{\link{to_tidy_names}} + +Other functions for internal use in other fgeo packages: \code{\link{flag_if}}, + \code{\link{guess_plotdim}}, \code{\link{is_named}}, + \code{\link{name_dfs}} +} +\concept{functions for internal use in other fgeo packages} +\concept{general functions to edit data in place} +\keyword{internal} diff --git a/man/to_tidy_names.Rd b/man/to_tidy_names.Rd index d985f420..5a438185 100644 --- a/man/to_tidy_names.Rd +++ b/man/to_tidy_names.Rd @@ -34,6 +34,6 @@ setNames(list(1), to_tidy_names(messy)) \code{fgeo.tool::nms_tidy()}. Other general functions to edit data in place: \code{\link{fill_na}}, - \code{\link{lookup}} + \code{\link{lookup}}, \code{\link{suffix_match}} } \concept{general functions to edit data in place} From ee41889c13894899eb0569ccf8fc343c1c02f3a9 Mon Sep 17 00:00:00 2001 From: maurolepore Date: Thu, 6 Dec 2018 10:16:32 -0500 Subject: [PATCH 2/8] Export %||% directly from rlang. --- NAMESPACE | 1 + R/imports-reeports.R | 4 +++- R/operators.R | 23 ----------------------- man/reexports.Rd | 3 +++ tests/testthat/test-operators.R | 8 -------- 5 files changed, 7 insertions(+), 32 deletions(-) delete mode 100644 R/operators.R delete mode 100644 tests/testthat/test-operators.R diff --git a/NAMESPACE b/NAMESPACE index a713fdf2..363b6cf3 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -16,6 +16,7 @@ S3method(to_df,demography_impl) S3method(to_df,krig_lst) S3method(to_df,tt_lst) export("%>%") +export("%||%") export(add_col_row) export(add_col_row2) export(add_count) diff --git a/R/imports-reeports.R b/R/imports-reeports.R index f58d4b82..1518df02 100644 --- a/R/imports-reeports.R +++ b/R/imports-reeports.R @@ -1,8 +1,10 @@ -#' @importFrom rlang set_names abort warn inform has_name %||% #' @importFrom glue glue glue_collapse #' @importFrom utils head tail #' @importFrom measurements conv_unit +#' @importFrom rlang set_names abort warn inform has_name %||% NULL +#' @export +rlang::`%||%` globalVariables(c(".data", ".")) diff --git a/R/operators.R b/R/operators.R deleted file mode 100644 index 0f222a9a..00000000 --- a/R/operators.R +++ /dev/null @@ -1,23 +0,0 @@ -#' Default value for `NULL`. -#' -#' This infix function makes it easy to replace `NULL`s with a default value. -#' It's inspired by the way that Ruby's or operation (||) works. It is slightly -#' adapted from `rlang::`%||%`. -#' -#' @param x,y If x is NULL, will return y; otherwise returns x. -#' @family general miscellaneous functions -#' -#' @keywords internal -#' @noRd -#' -#' @examples -#' 1 %||% 2 -#' NULL %||% 2 -#' @name op-null-default -`%||%` <- function (x, y) { - if (is.null(x)) { - y - } else { - x - } -} diff --git a/man/reexports.Rd b/man/reexports.Rd index b4333aee..46f997f6 100644 --- a/man/reexports.Rd +++ b/man/reexports.Rd @@ -3,6 +3,7 @@ \docType{import} \name{reexports} \alias{reexports} +\alias{\%||\%} \alias{filter} \alias{mutate} \alias{select} @@ -33,6 +34,8 @@ below to see their documentation. \describe{ \item{dplyr}{\code{\link[dplyr]{filter}}, \code{\link[dplyr]{mutate}}, \code{\link[dplyr]{select}}, \code{\link[dplyr]{arrange}}, \code{\link[dplyr]{summarize}}, \code{\link[dplyr]{summarise}}, \code{\link[dplyr]{group_by}}, \code{\link[dplyr]{ungroup}}, \code{\link[dplyr]{count}}, \code{\link[dplyr]{add_count}}} + \item{rlang}{\code{\link[rlang]{\%||\%}}} + \item{tibble}{\code{\link[tibble]{tibble}}, \code{\link[tibble]{tribble}}, \code{\link[tibble]{as_tibble}}} \item{tidyselect}{\code{\link[tidyselect]{starts_with}}, \code{\link[tidyselect]{ends_with}}, \code{\link[tidyselect]{contains}}, \code{\link[tidyselect]{matches}}, \code{\link[tidyselect]{num_range}}, \code{\link[tidyselect]{one_of}}, \code{\link[tidyselect]{everything}}, \code{\link[tidyselect]{last_col}}} diff --git a/tests/testthat/test-operators.R b/tests/testthat/test-operators.R deleted file mode 100644 index 7b2f1675..00000000 --- a/tests/testthat/test-operators.R +++ /dev/null @@ -1,8 +0,0 @@ -context("operators") - -test_that("outputs as expected", { - expect_identical(1 %||% 2, 1) - expect_identical(NULL %||% 2, 2) - expect_identical(NULL %||% NA, NA) - expect_identical(NA %||% 2, NA) -}) From d8051eefe8233262d200f7c258729191d30ff6a7 Mon Sep 17 00:00:00 2001 From: maurolepore Date: Thu, 6 Dec 2018 10:26:45 -0500 Subject: [PATCH 3/8] Hotfix: Export funcitons used in examples. --- NAMESPACE | 4 +++ R/flag_if.R | 6 ++--- R/is_duplicated.R | 6 ++--- man/check_crucial_names.Rd | 6 +++-- man/flag_if.Rd | 16 +++++++++--- man/flag_if_group.Rd | 3 ++- man/guess_plotdim.Rd | 4 +-- man/is_multiple.Rd | 51 ++++++++++++++++++++++++++++++++++++++ man/is_named.Rd | 6 +++-- man/name_dfs.Rd | 4 +-- man/nms.Rd | 1 + man/nms_extract_anycase.Rd | 2 +- man/nms_lowercase.Rd | 1 + man/nms_restore_newvar.Rd | 1 + man/nms_tidy.Rd | 1 + man/nms_try_rename.Rd | 1 + man/suffix_match.Rd | 4 +-- 17 files changed, 94 insertions(+), 23 deletions(-) create mode 100644 man/is_multiple.Rd diff --git a/NAMESPACE b/NAMESPACE index 363b6cf3..150d4e58 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -10,6 +10,8 @@ S3method(fgeo_elevation,list) S3method(fgeo_topography,data.frame) S3method(fgeo_topography,default) S3method(fgeo_topography,list) +S3method(flag_if,data.frame) +S3method(flag_if,default) S3method(print,censuses_lst) S3method(to_df,default) S3method(to_df,demography_impl) @@ -64,6 +66,8 @@ export(flag_if_group) export(group_by) export(guess_plotdim) export(hide_data_of_class) +export(is_duplicated) +export(is_multiple) export(is_named) export(last_col) export(list_csv) diff --git a/R/flag_if.R b/R/flag_if.R index 3526e7e1..ee7c3354 100644 --- a/R/flag_if.R +++ b/R/flag_if.R @@ -45,8 +45,7 @@ flag_if <- function(.data, ...) { } #' @rdname flag_if -#' @keywords internal -#' @noRd +#' @export flag_if.default <- function(.data, predicate, condition = warning, @@ -58,8 +57,7 @@ flag_if.default <- function(.data, } #' @rdname flag_if -#' @keywords internal -#' @noRd +#' @export flag_if.data.frame <- function(.data, name, predicate, diff --git a/R/is_duplicated.R b/R/is_duplicated.R index d37c45e2..14289a92 100644 --- a/R/is_duplicated.R +++ b/R/is_duplicated.R @@ -12,8 +12,9 @@ #' #' @return Logical. #' +#' @family functions for internal use in other fgeo packages #' @keywords internal -#' @noRd +#' @export #' #' @examples #' is_multiple(c(1, 2)) @@ -28,8 +29,7 @@ is_multiple <- function(.data) { } #' @rdname is_multiple -#' @keywords internal -#' @noRd +#' @export is_duplicated <- function(.data) { any(duplicated(.data)) } diff --git a/man/check_crucial_names.Rd b/man/check_crucial_names.Rd index 564a48d0..f07cc93f 100644 --- a/man/check_crucial_names.Rd +++ b/man/check_crucial_names.Rd @@ -25,9 +25,11 @@ dfm <- data.frame(x = 1) check_crucial_names(dfm, "x") } \seealso{ -Other functions to check inputs.: \code{\link{flag_if_group}} +Other functions to check inputs.: \code{\link{flag_if_group}}, + \code{\link{is_multiple}} -Other functions for developers: \code{\link{nms_extract_anycase}}, +Other functions for developers: \code{\link{is_multiple}}, + \code{\link{nms_extract_anycase}}, \code{\link{nms_lowercase}}, \code{\link{nms_restore_newvar}}, \code{\link{nms_tidy}}, \code{\link{nms_try_rename}}, \code{\link{nms}} diff --git a/man/flag_if.Rd b/man/flag_if.Rd index 59f16517..7a8cef1d 100644 --- a/man/flag_if.Rd +++ b/man/flag_if.Rd @@ -2,23 +2,31 @@ % Please edit documentation in R/flag_if.R \name{flag_if} \alias{flag_if} +\alias{flag_if.default} +\alias{flag_if.data.frame} \title{Flag if a vector or dataframe-column meets a condition.} \usage{ flag_if(.data, ...) + +\method{flag_if}{default}(.data, predicate, condition = warning, + msg = NULL, ...) + +\method{flag_if}{data.frame}(.data, name, predicate, condition = warning, + msg = NULL, ...) } \arguments{ \item{.data}{Vector.} \item{...}{Other arguments passed to methods.} -\item{name}{String. The name of a column of a dataframe.} - \item{predicate}{A predicate function.} \item{condition}{A condition function (e.g. \code{\link[=stop]{stop()}}, \code{\link[=warning]{warning()}}, \code{rlang::inform()}).} \item{msg}{String. An optional custom message.} + +\item{name}{String. The name of a column of a dataframe.} } \value{ A condition (and \code{.data} invisibly). @@ -52,8 +60,8 @@ flag_if(.df, "a", is_multiple, message, "Custom") } \seealso{ Other functions for internal use in other fgeo packages: \code{\link{guess_plotdim}}, - \code{\link{is_named}}, \code{\link{name_dfs}}, - \code{\link{suffix_match}} + \code{\link{is_multiple}}, \code{\link{is_named}}, + \code{\link{name_dfs}}, \code{\link{suffix_match}} } \concept{functions for internal use in other fgeo packages} \concept{functions to throw conditions} diff --git a/man/flag_if_group.Rd b/man/flag_if_group.Rd index 8bc54235..8fd75475 100644 --- a/man/flag_if_group.Rd +++ b/man/flag_if_group.Rd @@ -43,7 +43,8 @@ detect_if_group(by_censusid, "treeID", is_multiple) flag_if_group(by_censusid, "treeID", is_multiple) } \seealso{ -Other functions to check inputs.: \code{\link{check_crucial_names}} +Other functions to check inputs.: \code{\link{check_crucial_names}}, + \code{\link{is_multiple}} Other functions for developers.: \code{\link{find_data_of_class}}, \code{\link{type_ensure}} diff --git a/man/guess_plotdim.Rd b/man/guess_plotdim.Rd index 007f1cc7..07bb868b 100644 --- a/man/guess_plotdim.Rd +++ b/man/guess_plotdim.Rd @@ -35,8 +35,8 @@ Other functions for fgeo vft.: \code{\link{add_status_tree}}, \code{\link{add_var}}, \code{\link{pick_drop}} Other functions for internal use in other fgeo packages: \code{\link{flag_if}}, - \code{\link{is_named}}, \code{\link{name_dfs}}, - \code{\link{suffix_match}} + \code{\link{is_multiple}}, \code{\link{is_named}}, + \code{\link{name_dfs}}, \code{\link{suffix_match}} } \concept{functions for fgeo census and vft.} \concept{functions for fgeo census.} diff --git a/man/is_multiple.Rd b/man/is_multiple.Rd new file mode 100644 index 00000000..61912b55 --- /dev/null +++ b/man/is_multiple.Rd @@ -0,0 +1,51 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/is_duplicated.R +\name{is_multiple} +\alias{is_multiple} +\alias{is_duplicated} +\title{Predicates to detect and flag duplicated and multiple values of a variable.} +\usage{ +is_multiple(.data) + +is_duplicated(.data) +} +\arguments{ +\item{.data}{A vector.} +} +\value{ +Logical. +} +\description{ +\code{is_multiple()} and \code{is_duplicated()} return \code{TRUE} if they detect, +respectively, multiple different values of a variable (e.g. c(1, 2)\code{), or duplicated values of a variable (e.g. c(1, 1)}). +} +\examples{ +is_multiple(c(1, 2)) +is_multiple(c(1, 1)) +is_multiple(c(1, NA)) + +is_duplicated(c(1, 2)) +is_duplicated(c(1, 1)) +is_duplicated(c(1, NA)) +} +\seealso{ +Other functions to check inputs.: \code{\link{check_crucial_names}}, + \code{\link{flag_if_group}} + +Other functions for developers: \code{\link{check_crucial_names}}, + \code{\link{nms_extract_anycase}}, + \code{\link{nms_lowercase}}, + \code{\link{nms_restore_newvar}}, \code{\link{nms_tidy}}, + \code{\link{nms_try_rename}}, \code{\link{nms}} + +Other general predicates: \code{\link{is_named}} + +Other functions for internal use in other fgeo packages: \code{\link{flag_if}}, + \code{\link{guess_plotdim}}, \code{\link{is_named}}, + \code{\link{name_dfs}}, \code{\link{suffix_match}} +} +\concept{functions for developers} +\concept{functions for internal use in other fgeo packages} +\concept{functions to check inputs.} +\concept{general predicates} +\keyword{internal} diff --git a/man/is_named.Rd b/man/is_named.Rd index 659d80e1..3b6d689c 100644 --- a/man/is_named.Rd +++ b/man/is_named.Rd @@ -27,9 +27,11 @@ is_named(dfm) dfm } \seealso{ +Other general predicates: \code{\link{is_multiple}} + Other functions for internal use in other fgeo packages: \code{\link{flag_if}}, - \code{\link{guess_plotdim}}, \code{\link{name_dfs}}, - \code{\link{suffix_match}} + \code{\link{guess_plotdim}}, \code{\link{is_multiple}}, + \code{\link{name_dfs}}, \code{\link{suffix_match}} } \concept{functions for internal use in other fgeo packages} \concept{general predicates} diff --git a/man/name_dfs.Rd b/man/name_dfs.Rd index 3672418f..b3e646b1 100644 --- a/man/name_dfs.Rd +++ b/man/name_dfs.Rd @@ -29,8 +29,8 @@ name_dfs(dfs2) } \seealso{ Other functions for internal use in other fgeo packages: \code{\link{flag_if}}, - \code{\link{guess_plotdim}}, \code{\link{is_named}}, - \code{\link{suffix_match}} + \code{\link{guess_plotdim}}, \code{\link{is_multiple}}, + \code{\link{is_named}}, \code{\link{suffix_match}} } \concept{functions for internal use in other fgeo packages} \concept{general functions to deal with names} diff --git a/man/nms.Rd b/man/nms.Rd index a7e02d44..fcf97a46 100644 --- a/man/nms.Rd +++ b/man/nms.Rd @@ -62,6 +62,7 @@ nms_extract_all(stem, "gx", "gy", "PX", "PY") } \seealso{ Other functions for developers: \code{\link{check_crucial_names}}, + \code{\link{is_multiple}}, \code{\link{nms_extract_anycase}}, \code{\link{nms_lowercase}}, \code{\link{nms_restore_newvar}}, \code{\link{nms_tidy}}, diff --git a/man/nms_extract_anycase.Rd b/man/nms_extract_anycase.Rd index 0ad31622..41320d13 100644 --- a/man/nms_extract_anycase.Rd +++ b/man/nms_extract_anycase.Rd @@ -26,7 +26,7 @@ nms_extract_anycase(dfm, "b") } \seealso{ Other functions for developers: \code{\link{check_crucial_names}}, - \code{\link{nms_lowercase}}, + \code{\link{is_multiple}}, \code{\link{nms_lowercase}}, \code{\link{nms_restore_newvar}}, \code{\link{nms_tidy}}, \code{\link{nms_try_rename}}, \code{\link{nms}} diff --git a/man/nms_lowercase.Rd b/man/nms_lowercase.Rd index f7a33852..0b32dd7d 100644 --- a/man/nms_lowercase.Rd +++ b/man/nms_lowercase.Rd @@ -50,6 +50,7 @@ Other functions dealing with names: \code{\link{nms_extract_anycase}}, \code{\link{nms_try_rename}}, \code{\link{nms}} Other functions for developers: \code{\link{check_crucial_names}}, + \code{\link{is_multiple}}, \code{\link{nms_extract_anycase}}, \code{\link{nms_restore_newvar}}, \code{\link{nms_tidy}}, \code{\link{nms_try_rename}}, \code{\link{nms}} diff --git a/man/nms_restore_newvar.Rd b/man/nms_restore_newvar.Rd index 9ed03178..5638fca2 100644 --- a/man/nms_restore_newvar.Rd +++ b/man/nms_restore_newvar.Rd @@ -62,6 +62,7 @@ Other functions dealing with names: \code{\link{nms_extract_anycase}}, \code{\link{nms_try_rename}}, \code{\link{nms}} Other functions for developers: \code{\link{check_crucial_names}}, + \code{\link{is_multiple}}, \code{\link{nms_extract_anycase}}, \code{\link{nms_lowercase}}, \code{\link{nms_tidy}}, \code{\link{nms_try_rename}}, \code{\link{nms}} diff --git a/man/nms_tidy.Rd b/man/nms_tidy.Rd index dc191f25..9dd91cc8 100644 --- a/man/nms_tidy.Rd +++ b/man/nms_tidy.Rd @@ -54,6 +54,7 @@ Other functions dealing with names: \code{\link{nms_extract_anycase}}, \code{\link{nms_try_rename}}, \code{\link{nms}} Other functions for developers: \code{\link{check_crucial_names}}, + \code{\link{is_multiple}}, \code{\link{nms_extract_anycase}}, \code{\link{nms_lowercase}}, \code{\link{nms_restore_newvar}}, diff --git a/man/nms_try_rename.Rd b/man/nms_try_rename.Rd index 1d58fa12..5aade5a5 100644 --- a/man/nms_try_rename.Rd +++ b/man/nms_try_rename.Rd @@ -37,6 +37,7 @@ Other functions dealing with names: \code{\link{nms_extract_anycase}}, \code{\link{nms}} Other functions for developers: \code{\link{check_crucial_names}}, + \code{\link{is_multiple}}, \code{\link{nms_extract_anycase}}, \code{\link{nms_lowercase}}, \code{\link{nms_restore_newvar}}, \code{\link{nms_tidy}}, diff --git a/man/suffix_match.Rd b/man/suffix_match.Rd index c750fcf7..ac9f0b6f 100644 --- a/man/suffix_match.Rd +++ b/man/suffix_match.Rd @@ -48,8 +48,8 @@ Other general functions to edit data in place: \code{\link{fill_na}}, \code{\link{lookup}}, \code{\link{to_tidy_names}} Other functions for internal use in other fgeo packages: \code{\link{flag_if}}, - \code{\link{guess_plotdim}}, \code{\link{is_named}}, - \code{\link{name_dfs}} + \code{\link{guess_plotdim}}, \code{\link{is_multiple}}, + \code{\link{is_named}}, \code{\link{name_dfs}} } \concept{functions for internal use in other fgeo packages} \concept{general functions to edit data in place} From 3860f2fefad039941b5fff4e532d355c907cd4e1 Mon Sep 17 00:00:00 2001 From: maurolepore Date: Thu, 6 Dec 2018 10:31:59 -0500 Subject: [PATCH 4/8] move functions to packags that use them: * Move collapse_censusid to fgeo.map. * Move has_table_names to fgeo.habitat. --- R/collapse_censusid.R | 36 ------------------------- R/has_table_names.R | 20 -------------- tests/testthat/test-collapse_censusid.R | 20 -------------- tests/testthat/test-has_table_names.R | 18 ------------- 4 files changed, 94 deletions(-) delete mode 100644 R/collapse_censusid.R delete mode 100644 R/has_table_names.R delete mode 100644 tests/testthat/test-collapse_censusid.R delete mode 100644 tests/testthat/test-has_table_names.R diff --git a/R/collapse_censusid.R b/R/collapse_censusid.R deleted file mode 100644 index 28a3f142..00000000 --- a/R/collapse_censusid.R +++ /dev/null @@ -1,36 +0,0 @@ -#' Collapse the values of CensusID. -#' -#' This function is useful to summarize the status history of a tree tag across -#' censuses. It is particularly useful to avoid duplicated tree tags on maps. -#' -#' @param x A dataframe -- specifically a ViewFullTable. -#' -#' @family functions to edit ForestGEO data in place -#' @keywords internal -#' -#' @return A modified version of `x`, most likely with less rows. -#' @keywords internal -#' @noRd -#' -#' @examples -#' x <- data.frame( -#' CensusID = c(1, 1, 1, 1, 2, 2, 2, 2), -#' Tag = c(1, 1, 2, 2, 1, 1, 2, 2), -#' Status = c("alive", "dead", "dead", "dead", "alive", "alive", "alive", "dead"), -#' stringsAsFactors = FALSE -#' ) -#' x -#' collapse_censusid(x) -collapse_censusid <- function(x) { - stopifnot(is.data.frame(x)) - - old <- names(x) - names(x) <- tolower(old) - check_crucial_names(x, "censusid") - - x$censusid <- glue_comma(sort(unique(x$censusid))) - - x <- stats::setNames(x, old) - unique(x) -} - diff --git a/R/has_table_names.R b/R/has_table_names.R deleted file mode 100644 index 8b95f396..00000000 --- a/R/has_table_names.R +++ /dev/null @@ -1,20 +0,0 @@ -#' Factory of predicates to check if a table has the same names as a reference. -#' -#' @param reference A dataframe. -#' @family general predicates -#' -#' @return A closure. -#' @keywords internal -#' @noRd -#' @examples -#' stem <- data.frame(x = 1, y = 1) -#' tree <- data.frame(x = 1, z = 1) -#' has_table_names(stem)(stem) -#' has_table_names(stem)(tree) -#' @name has_table_names -has_table_names <- function(reference) { - function(.data) { - has_expected_names <- all(utils::hasName(.data, names(reference))) - if (has_expected_names) TRUE else FALSE - } -} diff --git a/tests/testthat/test-collapse_censusid.R b/tests/testthat/test-collapse_censusid.R deleted file mode 100644 index 6df8f5f2..00000000 --- a/tests/testthat/test-collapse_censusid.R +++ /dev/null @@ -1,20 +0,0 @@ -x <- data.frame( - CensusID = c(1, 1, 1, 1, 2, 2, 2, 2), - TreeID = c(1, 1, 2, 2, 1, 1, 2, 2), - Tag = c(1, 1, 2, 2, 1, 1, 2, 2), - Status = c("alive", "dead", "dead", "dead", "alive", "alive", "alive", "dead"), - stringsAsFactors = FALSE -) - -context("collapse_censusid") - -test_that("outputs object of expected status and status_tree", { - skip_if_not_installed("fgeo.tool") - expect_equal(collapse_censusid(x)$Status, c("alive", rep("dead", 2), "alive")) - x <- fgeo.tool::add_status_tree(x, "alive", "dead") - x$Status <- NULL - collapsed <- collapse_censusid(unique(x)) - expected_status_tree <- c("alive", "dead", "alive") - expect_equal(collapsed$status_tree, expected_status_tree) -}) - diff --git a/tests/testthat/test-has_table_names.R b/tests/testthat/test-has_table_names.R deleted file mode 100644 index 24cf68b2..00000000 --- a/tests/testthat/test-has_table_names.R +++ /dev/null @@ -1,18 +0,0 @@ -context("has_table_names") - -test_that("returns TRUE with a tree table and FALSE with other tables", { - skip_if_not_installed("fgeo.data") - - tree <- fgeo.data::luquillo_tree6_1ha - stem <- fgeo.data::luquillo_stem6_1ha - vft <- fgeo.data::luquillo_vft_4quad - taxa <- fgeo.data::luquillo_taxa - spp <- fgeo.data::luquillo_species - - expect_false(has_table_names(tree)(stem)) - expect_true(has_table_names(tree)(tree)) - expect_true(has_table_names(stem)(stem)) - expect_true(has_table_names(vft)(vft)) - expect_true(has_table_names(spp)(spp)) - expect_true(has_table_names(taxa)(taxa)) -}) From ee3b6222ecc6cd0b0baa2d73e6c91185cbbf8a13 Mon Sep 17 00:00:00 2001 From: maurolepore Date: Thu, 6 Dec 2018 11:21:15 -0500 Subject: [PATCH 5/8] Remove fgeo.base from DESCRIPTION. --- DESCRIPTION | 2 - R/flag_if_group.R | 4 +- Rplots.pdf | Bin 0 -> 4972 bytes docs/reference/check_crucial_names.html | 6 +- docs/reference/flag_if.html | 39 +++-- docs/reference/flag_if_group.html | 12 +- docs/reference/guess_plotdim.html | 4 +- docs/reference/is_multiple.html | 190 ++++++++++++++++++++++++ docs/reference/is_named.html | 7 +- docs/reference/name_dfs.html | 4 +- docs/reference/nms.html | 1 + docs/reference/nms_extract_anycase.html | 2 +- docs/reference/nms_lowercase.html | 1 + docs/reference/nms_restore_newvar.html | 1 + docs/reference/nms_tidy.html | 1 + docs/reference/nms_try_rename.html | 1 + docs/reference/reexports.html | 4 + docs/reference/suffix_match.html | 4 +- docs/sitemap.xml | 3 + man/flag_if_group.Rd | 4 +- tests/testthat/test-flag_if_group.R | 1 - tests/testthat/test-guess_plotdim.R | 19 ++- 22 files changed, 261 insertions(+), 49 deletions(-) create mode 100644 Rplots.pdf create mode 100644 docs/reference/is_multiple.html diff --git a/DESCRIPTION b/DESCRIPTION index e9d6e8e9..09579a31 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -26,7 +26,6 @@ Depends: Imports: cli, dplyr, - fgeo.base, fgeo.ctfs, fgeo.x, fs, @@ -55,7 +54,6 @@ Suggests: VignetteBuilder: knitr Remotes: - forestgeo/fgeo.base, forestgeo/fgeo.ctfs, forestgeo/fgeo.habitat, forestgeo/fgeo.map, diff --git a/R/flag_if_group.R b/R/flag_if_group.R index c142c5c4..25a895dc 100644 --- a/R/flag_if_group.R +++ b/R/flag_if_group.R @@ -1,6 +1,6 @@ #' Detect and flag based on a predicate applied to a variable by groups. #' -#' These functions extend [flag_if()] and [detect_if()] to +#' These functions extend `flag_if()`] and `detect_if()` to #' work by groups defined with [dplyr::group_by()]. #' #' @param .data A dataframe. @@ -21,8 +21,6 @@ #' @export #' #' @examples -#' library(fgeo.base) -#' #' tree <- tibble(CensusID = c(1, 2), treeID = c(1, 2)) #' detect_if_group(tree, "treeID", is_multiple) #' flag_if_group(tree, "treeID", is_multiple) diff --git a/Rplots.pdf b/Rplots.pdf new file mode 100644 index 0000000000000000000000000000000000000000..eede389b7283338ab703cfe19e0aba9106e0253a GIT binary patch literal 4972 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 literal 0 HcmV?d00001 diff --git a/docs/reference/check_crucial_names.html b/docs/reference/check_crucial_names.html index 324b4882..517fd8c6 100644 --- a/docs/reference/check_crucial_names.html +++ b/docs/reference/check_crucial_names.html @@ -140,8 +140,10 @@

Value

See also

-

Other functions to check inputs.: flag_if_group

-

Other functions for developers: nms_extract_anycase, +

Other functions to check inputs.: flag_if_group, + is_multiple

+

Other functions for developers: is_multiple, + nms_extract_anycase, nms_lowercase, nms_restore_newvar, nms_tidy, nms_try_rename, nms

diff --git a/docs/reference/flag_if.html b/docs/reference/flag_if.html index 2c0429fe..d4f35238 100644 --- a/docs/reference/flag_if.html +++ b/docs/reference/flag_if.html @@ -123,7 +123,15 @@

Flag if a vector or dataframe-column meets a condition.

-
flag_if(.data, ...)
+
flag_if(.data, ...)
+
+# S3 method for default
+flag_if(.data, predicate, condition = warning,
+  msg = NULL, ...)
+
+# S3 method for data.frame
+flag_if(.data, name, predicate, condition = warning,
+  msg = NULL, ...)

Arguments

@@ -136,10 +144,6 @@

Arg

- - - - @@ -153,6 +157,10 @@

Arg

+ + + +
...

Other arguments passed to methods.

name

String. The name of a column of a dataframe.

predicate

A predicate function.

msg

String. An optional custom message.

name

String. The name of a column of a dataframe.

Value

@@ -162,23 +170,28 @@

Value

See also

Other functions for internal use in other fgeo packages: guess_plotdim, - is_named, name_dfs, - suffix_match

+ is_multiple, is_named, + name_dfs, suffix_match

Examples

# WITH VECTORS dupl <- c(1, 1) -flag_if(dupl, is_duplicated)
#> Error in UseMethod("flag_if"): no applicable method for 'flag_if' applied to an object of class "c('double', 'numeric')"
# Silent -flag_if(dupl, is_multiple)
#> Error in UseMethod("flag_if"): no applicable method for 'flag_if' applied to an object of class "c('double', 'numeric')"
+flag_if(dupl, is_duplicated)
#> Warning: Flagged values were detected.
# Silent +flag_if(dupl, is_multiple) + mult <- c(1, 2) -flag_if(mult, is_multiple, message, "Custom")
#> Error in UseMethod("flag_if"): no applicable method for 'flag_if' applied to an object of class "c('double', 'numeric')"
# Silent -flag_if(mult, is_duplicated)
#> Error in UseMethod("flag_if"): no applicable method for 'flag_if' applied to an object of class "c('double', 'numeric')"
+flag_if(mult, is_multiple, message, "Custom")
#> Custom
# Silent +flag_if(mult, is_duplicated) + # Both silent -flag_if(c(1, NA), is_multiple)
#> Error in UseMethod("flag_if"): no applicable method for 'flag_if' applied to an object of class "c('double', 'numeric')"
flag_if(c(1, NA), is_duplicated)
#> Error in UseMethod("flag_if"): no applicable method for 'flag_if' applied to an object of class "c('double', 'numeric')"
+flag_if(c(1, NA), is_multiple) +flag_if(c(1, NA), is_duplicated) + # WITH DATAFRAMES .df <- data.frame(a = 1:3, b = 1, stringsAsFactors = FALSE) -flag_if(.df, "b", is_multiple)
#> Error in UseMethod("flag_if"): no applicable method for 'flag_if' applied to an object of class "data.frame"
flag_if(.df, "a", is_multiple)
#> Error in UseMethod("flag_if"): no applicable method for 'flag_if' applied to an object of class "data.frame"
flag_if(.df, "a", is_multiple, message, "Custom")
#> Error in UseMethod("flag_if"): no applicable method for 'flag_if' applied to an object of class "data.frame"
+flag_if(.df, "b", is_multiple) +flag_if(.df, "a", is_multiple)

#> Warning: a: Flagged values were detected.
flag_if(.df, "a", is_multiple, message, "Custom")
#> Custom

Examples

diff --git a/docs/reference/nms.html b/docs/reference/nms.html index be4ef915..1eef7fae 100644 --- a/docs/reference/nms.html +++ b/docs/reference/nms.html @@ -161,6 +161,7 @@

Details

See also

Other functions for developers: check_crucial_names, + is_multiple, nms_extract_anycase, nms_lowercase, nms_restore_newvar, nms_tidy, diff --git a/docs/reference/nms_extract_anycase.html b/docs/reference/nms_extract_anycase.html index cda1e4fd..6b6d4feb 100644 --- a/docs/reference/nms_extract_anycase.html +++ b/docs/reference/nms_extract_anycase.html @@ -141,7 +141,7 @@

Value

See also

Other functions for developers: check_crucial_names, - nms_lowercase, + is_multiple, nms_lowercase, nms_restore_newvar, nms_tidy, nms_try_rename, nms

Other functions dealing with names: nms_lowercase, diff --git a/docs/reference/nms_lowercase.html b/docs/reference/nms_lowercase.html index f8df4ed8..f67ceed8 100644 --- a/docs/reference/nms_lowercase.html +++ b/docs/reference/nms_lowercase.html @@ -160,6 +160,7 @@

See a nms_restore_newvar, nms_tidy, nms_try_rename, nms

Other functions for developers: check_crucial_names, + is_multiple, nms_extract_anycase, nms_restore_newvar, nms_tidy, nms_try_rename, nms

diff --git a/docs/reference/nms_restore_newvar.html b/docs/reference/nms_restore_newvar.html index d27e0a3d..dbcd794e 100644 --- a/docs/reference/nms_restore_newvar.html +++ b/docs/reference/nms_restore_newvar.html @@ -171,6 +171,7 @@

See a nms_lowercase, nms_tidy, nms_try_rename, nms

Other functions for developers: check_crucial_names, + is_multiple, nms_extract_anycase, nms_lowercase, nms_tidy, nms_try_rename, nms

diff --git a/docs/reference/nms_tidy.html b/docs/reference/nms_tidy.html index 1d7d258e..eca4922d 100644 --- a/docs/reference/nms_tidy.html +++ b/docs/reference/nms_tidy.html @@ -147,6 +147,7 @@

See a nms_restore_newvar, nms_try_rename, nms

Other functions for developers: check_crucial_names, + is_multiple, nms_extract_anycase, nms_lowercase, nms_restore_newvar, diff --git a/docs/reference/nms_try_rename.html b/docs/reference/nms_try_rename.html index 1b0a7635..8d180a22 100644 --- a/docs/reference/nms_try_rename.html +++ b/docs/reference/nms_try_rename.html @@ -148,6 +148,7 @@

See a nms_restore_newvar, nms_tidy, nms

Other functions for developers: check_crucial_names, + is_multiple, nms_extract_anycase, nms_lowercase, nms_restore_newvar, nms_tidy, diff --git a/docs/reference/reexports.html b/docs/reference/reexports.html index 40e57479..2c1e6c6f 100644 --- a/docs/reference/reexports.html +++ b/docs/reference/reexports.html @@ -37,6 +37,8 @@ dplyrfilter, mutate, select, arrange, summarize, summarise, group_by, ungroup, count, add_count" /> + + See a

Other general functions to edit data in place: fill_na, lookup, to_tidy_names

Other functions for internal use in other fgeo packages: flag_if, - guess_plotdim, is_named, - name_dfs

+ guess_plotdim, is_multiple, + is_named, name_dfs

Examples

diff --git a/docs/sitemap.xml b/docs/sitemap.xml index 2ff46a17..895bb2b9 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -63,6 +63,9 @@ https://forestgeo.github.io/fgeo.tool//reference/guess_plotdim.html + + https://forestgeo.github.io/fgeo.tool//reference/is_multiple.html + https://forestgeo.github.io/fgeo.tool//reference/is_named.html diff --git a/man/flag_if_group.Rd b/man/flag_if_group.Rd index 8fd75475..8bed4eb5 100644 --- a/man/flag_if_group.Rd +++ b/man/flag_if_group.Rd @@ -28,12 +28,10 @@ detect_if_group(.data, name, predicate) } } \description{ -These functions extend \code{\link[=flag_if]{flag_if()}} and \code{\link[=detect_if]{detect_if()}} to +These functions extend \code{flag_if()}] and \code{detect_if()} to work by groups defined with \code{\link[dplyr:group_by]{dplyr::group_by()}}. } \examples{ -library(fgeo.base) - tree <- tibble(CensusID = c(1, 2), treeID = c(1, 2)) detect_if_group(tree, "treeID", is_multiple) flag_if_group(tree, "treeID", is_multiple) diff --git a/tests/testthat/test-flag_if_group.R b/tests/testthat/test-flag_if_group.R index 59074257..8819f56a 100644 --- a/tests/testthat/test-flag_if_group.R +++ b/tests/testthat/test-flag_if_group.R @@ -1,7 +1,6 @@ context("flag_if_group") library(dplyr) -library(fgeo.base) describe("detect_if_group() and flag_if_group()", { msg <- "Flagged values were detected" diff --git a/tests/testthat/test-guess_plotdim.R b/tests/testthat/test-guess_plotdim.R index 0ab23265..81441aae 100644 --- a/tests/testthat/test-guess_plotdim.R +++ b/tests/testthat/test-guess_plotdim.R @@ -19,16 +19,15 @@ test_that("outputs expected plotdim and message", { context("test-nms_pull_matches") -describe("nms_pull_matches", { - it("pulls the expected names", { - vft <- luquillo_stem_random_tiny - expected <- c("gx", "gy") - expect_equal(nms_pull_matches(vft, c("x", "PX", "gx", "gy")), expected) - }) - - it("fails with unnamed input", { - expect_error(nms_pull_matches("unnnamed", "x"), "is not TRUE") - }) +test_that("pulls the expected names", { + skip_if_not_installed("fgeo.data") + vft <- fgeo.data::luquillo_stem_random_tiny + expected <- c("gx", "gy") + expect_equal(nms_pull_matches(vft, c("x", "PX", "gx", "gy")), expected) +}) + +test_that("fails with unnamed input", { + expect_error(nms_pull_matches("unnnamed", "x"), "is not TRUE") }) From fe72073e75a019d6a9cec520f0d153ef7ff8ebfc Mon Sep 17 00:00:00 2001 From: maurolepore Date: Thu, 6 Dec 2018 16:39:37 -0500 Subject: [PATCH 6/8] Depend on fgeo.ctfs. --- .buildignore/tmp.R | 20 +-- NAMESPACE | 3 +- R/add_var.R | 2 +- R/check_crucial_names.R | 69 ---------- R/guess_plotdim.R | 96 -------------- R/imports-reeports.R | 4 + R/round_any.R | 29 ----- R/utils.R | 11 +- R/warn_na.R | 6 +- Rplots.pdf | Bin 4972 -> 0 bytes docs/reference/add_status_tree.html | 4 +- docs/reference/add_var.html | 4 +- docs/reference/flag_if.html | 3 +- docs/reference/flag_if_group.html | 16 +-- docs/reference/is_multiple.html | 8 +- docs/reference/name_dfs.html | 3 +- docs/reference/nms.html | 3 +- docs/reference/nms_extract_anycase.html | 4 +- docs/reference/nms_lowercase.html | 3 +- docs/reference/nms_restore_newvar.html | 3 +- docs/reference/nms_tidy.html | 3 +- docs/reference/nms_try_rename.html | 3 +- docs/reference/pick_drop.html | 5 +- docs/reference/reexports.html | 4 + docs/reference/round_any.html | 149 ++++++++++++++++++++++ docs/reference/suffix_match.html | 3 +- docs/sitemap.xml | 9 -- man/add_status_tree.Rd | 4 +- man/add_var.Rd | 4 +- man/check_crucial_names.Rd | 41 ------ man/flag_if.Rd | 3 +- man/flag_if_group.Rd | 3 +- man/guess_plotdim.Rd | 46 ------- man/is_multiple.Rd | 9 +- man/is_named.Rd | 38 ------ man/name_dfs.Rd | 3 +- man/nms.Rd | 3 +- man/nms_extract_anycase.Rd | 4 +- man/nms_lowercase.Rd | 3 +- man/nms_restore_newvar.Rd | 3 +- man/nms_tidy.Rd | 3 +- man/nms_try_rename.Rd | 3 +- man/pick_drop.Rd | 6 +- man/reexports.Rd | 3 + man/suffix_match.Rd | 3 +- tests/testthat/test-check_crucial_names.R | 8 -- tests/testthat/test-guess_plotdim.R | 40 ------ 47 files changed, 219 insertions(+), 478 deletions(-) delete mode 100644 R/check_crucial_names.R delete mode 100644 R/guess_plotdim.R delete mode 100644 R/round_any.R delete mode 100644 Rplots.pdf create mode 100644 docs/reference/round_any.html delete mode 100644 man/check_crucial_names.Rd delete mode 100644 man/guess_plotdim.Rd delete mode 100644 man/is_named.Rd delete mode 100644 tests/testthat/test-check_crucial_names.R delete mode 100644 tests/testthat/test-guess_plotdim.R diff --git a/.buildignore/tmp.R b/.buildignore/tmp.R index fcdb31f2..f4da2325 100644 --- a/.buildignore/tmp.R +++ b/.buildignore/tmp.R @@ -1,24 +1,8 @@ # TODO: -# Remove useless roxygen complexity? -#' @rdname flag_if -#' @keywords internal -#' @noRd - - - -# https://github.com/forestgeo/fgeo.tool/issues/96 -# * Export functions that are used more than once -# check_crucial_names -# flag_if -# guess_plotdim -# name_dfs -# suffix_match - -# * Move functions that are used exactly once. -all other - +Package by package, disconnect fgeo.base from DESCRIPTION and all code +# Remove useless roxygen complexity? # Stuff ------------------------------------------------------------------- diff --git a/NAMESPACE b/NAMESPACE index 150d4e58..f78b13bc 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -64,11 +64,9 @@ export(filter_status) export(flag_if) export(flag_if_group) export(group_by) -export(guess_plotdim) export(hide_data_of_class) export(is_duplicated) export(is_multiple) -export(is_named) export(last_col) export(list_csv) export(list_df) @@ -148,6 +146,7 @@ importFrom(dplyr,select) importFrom(dplyr,summarise) importFrom(dplyr,summarize) importFrom(dplyr,ungroup) +importFrom(fgeo.ctfs,check_crucial_names) importFrom(glue,glue) importFrom(glue,glue_collapse) importFrom(magrittr,"%>%") diff --git a/R/add_var.R b/R/add_var.R index 2c8ae508..7f2ae9c7 100644 --- a/R/add_var.R +++ b/R/add_var.R @@ -56,7 +56,7 @@ add_var <- function(x, var, gridsize = 20, plotdim = NULL) { if (is.null(plotdim)) { plotdim <- plotdim - plotdim <- guess_plotdim(.x) + plotdim <- fgeo.ctfs::guess_plotdim(.x) message("* If guess is wrong, provide the correct argument `plotdim`") } diff --git a/R/check_crucial_names.R b/R/check_crucial_names.R deleted file mode 100644 index 7fceef5f..00000000 --- a/R/check_crucial_names.R +++ /dev/null @@ -1,69 +0,0 @@ -#' Check if an object contains specific names. -#' -#' @param x A named object. -#' @param nms String; names expected to be found in `x`. -#' -#' @family functions to check inputs. -#' @family functions for developers -#' @family general functions to assert -#' -#' -#' @return Invisible `x`, or an error with informative message. -#' -#' @family exported functions for internal use -#' @export -#' @keywords internal -#' -#' @examples -#' v <- c(x = 1) -#' check_crucial_names(v, "x") -#' -#' dfm <- data.frame(x = 1) -#' check_crucial_names(dfm, "x") -check_crucial_names <- function(x, nms) { - stopifnot(is_named(x)) - stopifnot(is.character(nms)) - - are_names_expected <- all(nms %in% names(x)) - if (are_names_expected) { - return(invisible(x)) - } - - stop( - "Ensure your data set has these variables:\n", glue_comma(nms), - call. = FALSE - ) -} - -#' Is named object? (Base-only version of rlang::is_named). -#' -#' @param x An object to test. -#' -#' @family general predicates -#' -#' @return The scalar `TRUE` or `FALSE`. -#' -#' @family functions for internal use in other fgeo packages -#' @keywords internal -#' @export -#' -#' @examples -#' is_named(c(x = 1)) -#' is_named(c(1)) -#' is_named(x = 1) -#' -#' is_named(data.frame(x = 1)) -#' -#' dfm <- data.frame(1) -#' is_named(dfm) -#' dfm -is_named <- function (x) { - nms <- names(x) - if (is.null(nms)) { - return(FALSE) - } - if (any(nms == "" | is.na(nms))) { - return(FALSE) - } - TRUE -} diff --git a/R/guess_plotdim.R b/R/guess_plotdim.R deleted file mode 100644 index 0b639dbc..00000000 --- a/R/guess_plotdim.R +++ /dev/null @@ -1,96 +0,0 @@ -#' Guess plot dimensions. -#' -#' @param x A dataframe; a ForestGEO dataset (census or ViewFullTable). -#' @param accuracy A number giving the accuracy with which to round `gx` and -#' `gy`. -#' -#' @return A numeric vector of length 2. -#' -#' @family functions for fgeo census and vft. -#' @family functions for fgeo census. -#' @family functions for fgeo vft. -#' @family general functions to find or approximate -#' @family functions for internal use in other fgeo packages -#' @keywords internal -#' @export -#' -#' @examples -#' x <- data.frame( -#' gx = c(0, 300, 979), -#' gy = c(0, 300, 481) -#' ) -#' guess_plotdim(x) -guess_plotdim <- function(x, accuracy = 20) { - stopifnot(is.data.frame(x)) - stopifnot(is.numeric(accuracy)) - - names(x) <- tolower(names(x)) - .match <- c("x", "gx", "y", "gy", "x", "px") - matched <- nms_pull_matches(x, .match) - - n_nms <- length(matched) - if (n_nms != 2) { - stop("Not enough columns to find x/y positions.\n", matched, call. = FALSE) - } - - guess <- vapply( - x[ , c("gx", "gy")], guess_max, double(1), accuracy = accuracy - ) - - message("Guessing: plotdim = c(", glue_comma(guess), ")") - unname(guess) -} - -#' Pull names that match a character vector. -#' -#' The `nms_` prefix matches functions in other fgeo packages. -#' -#' @param x A named object. -#' @param .match A character vector giving names to match. -#' -#' @family general functions to deal with names -#' @family functions for developers -#' -#' @return A character vector. -#' -#' @keywords internal -#' @noRd -#' @examples -#' nms_pull_matches(luquillo_stem_random_tiny, c("x", "PX", "gx")) -#' nms_pull_matches(luquillo_vft_4quad, c("x", "PX", "gx")) -#' nms_pull_matches(luquillo_vft_4quad, c("PY", "PX", "gx", "gy")) -nms_pull_matches <- function(x, .match) { - stopifnot(is_named(x)) - names(x)[grepl(glue_pipe(anchor(.match)), names(x))] -} - -anchor <- function(x) { - paste0("^", x, "$") -} - -glue_comma <- function(...) { - paste0(..., collapse = ", ") -} - -glue_pipe <- function(...) { - paste0(..., collapse = "|") -} - -#' Guess maximum value of a vector with flexible accuracy. -#' -#' @param x Numeric vector. -#' @param accuracy A single number. -#' -#' @family general functions to find or approximate -#' -#' @return A number. -#' -#' @keywords internal -#' @noRd -#' @examples -#' guess_max(1:19, 20) -guess_max <- function(x, accuracy) { - max_x <- max(x, na.rm = TRUE) - round_any(max_x, f = ceiling, accuracy = accuracy) -} - diff --git a/R/imports-reeports.R b/R/imports-reeports.R index 1518df02..02599ba9 100644 --- a/R/imports-reeports.R +++ b/R/imports-reeports.R @@ -1,9 +1,13 @@ #' @importFrom glue glue glue_collapse #' @importFrom utils head tail #' @importFrom measurements conv_unit +#' +#' @importFrom fgeo.ctfs check_crucial_names #' @importFrom rlang set_names abort warn inform has_name %||% NULL #' @export +fgeo.ctfs::check_crucial_names +#' @export rlang::`%||%` globalVariables(c(".data", ".")) diff --git a/R/round_any.R b/R/round_any.R deleted file mode 100644 index 9f17ae93..00000000 --- a/R/round_any.R +++ /dev/null @@ -1,29 +0,0 @@ -#' Round to multiple of any number. Copied from `plyr:::round_any.numeric()`. -#' -#' @param x Numeric vector to round. -#' @param accuracy Number to round to. -#' @param f Rounding function: floor, ceiling or round. -#' -#' @seealso `plyr::round_any()` and \url{http://bit.ly/2JrBQK3}. -#' @family functions for developers -#' @family functions dealing with names. -#' @family functions for developers with no dependencies. -#' @family general functions to find or approximate -#' -#' @keywords internal -#' @noRd -#' -#' @examples -#' # From pryr::round_any() -#' round_any(135, 10) -#' round_any(135, 100) -#' round_any(135, 25) -#' round_any(135, 10, floor) -#' round_any(135, 100, floor) -#' round_any(135, 25, floor) -#' round_any(135, 10, ceiling) -#' round_any(135, 100, ceiling) -#' round_any(135, 25, ceiling) -round_any <- function(x, accuracy, f = round) { - f(x / accuracy) * accuracy -} diff --git a/R/utils.R b/R/utils.R index ae451088..845e60c1 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,5 +1,12 @@ -commas <- function(...) { - paste0(..., collapse = ", ") +anchor <- function(x) paste0("^", x, "$") + +commas <- function(...) paste0(..., collapse = ", ") +glue_comma <- commas + +#' Round to multiple of any number. Copied from `plyr:::round_any.numeric()`. +#' @noRd +round_any <- function(x, accuracy, f = round) { + f(x / accuracy) * accuracy } has_class_df <- function(x) { diff --git a/R/warn_na.R b/R/warn_na.R index e5a1171f..c9441957 100644 --- a/R/warn_na.R +++ b/R/warn_na.R @@ -11,12 +11,16 @@ #' @name condition_na #' @noRd warn_na <- function(x) { - stopifnot(is.data.frame(x) || is.vector(x), !is.null(names(x)), is_named(x)) + stopifnot( + is.data.frame(x) || is.vector(x), + !is.null(names(x)), rlang::is_named(x) + ) out <- vapply(x, function(x) any(is.na(x)), logical(1)) has_na <- out if (any(has_na)) { warning("Detected missing values in: ", glue_comma(names(x)[has_na])) } + invisible(x) } diff --git a/Rplots.pdf b/Rplots.pdf deleted file mode 100644 index eede389b7283338ab703cfe19e0aba9106e0253a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4972 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 diff --git a/docs/reference/add_status_tree.html b/docs/reference/add_status_tree.html index ea18793f..f0a72534 100644 --- a/docs/reference/add_status_tree.html +++ b/docs/reference/add_status_tree.html @@ -147,9 +147,9 @@

See a

Other functions for ForestGEO data.: add_subquad, add_var

Other functions for fgeo census.: add_var, - guess_plotdim, pick_drop

+ pick_drop

Other functions for fgeo vft.: add_var, - guess_plotdim, pick_drop

+ pick_drop

Examples

diff --git a/docs/reference/add_var.html b/docs/reference/add_var.html index 47d3d8d5..341479dc 100644 --- a/docs/reference/add_var.html +++ b/docs/reference/add_var.html @@ -179,9 +179,9 @@

See a

Other functions for ForestGEO data.: add_status_tree, add_subquad

Other functions for fgeo census.: add_status_tree, - guess_plotdim, pick_drop

+ pick_drop

Other functions for fgeo vft.: add_status_tree, - guess_plotdim, pick_drop

+ pick_drop

Examples

diff --git a/docs/reference/flag_if.html b/docs/reference/flag_if.html index d4f35238..02849564 100644 --- a/docs/reference/flag_if.html +++ b/docs/reference/flag_if.html @@ -169,8 +169,7 @@

Value

See also

-

Other functions for internal use in other fgeo packages: guess_plotdim, - is_multiple, is_named, +

Other functions for internal use in other fgeo packages: is_multiple, name_dfs, suffix_match

diff --git a/docs/reference/flag_if_group.html b/docs/reference/flag_if_group.html index 0ffbc054..f048dc6d 100644 --- a/docs/reference/flag_if_group.html +++ b/docs/reference/flag_if_group.html @@ -32,7 +32,7 @@ - @@ -116,7 +116,7 @@

Detect and flag based on a predicate applied to a variable by groups.

-

These functions extend flag_if() and detect_if() to +

These functions extend flag_if()] and detect_if() to work by groups defined with dplyr::group_by().

@@ -162,21 +162,13 @@

Value

See also

-

Other functions to check inputs.: check_crucial_names, - is_multiple

+

Other functions to check inputs.: is_multiple

Other functions for developers.: find_data_of_class, type_ensure

Examples

-
library(fgeo.base)
#> -#> Attaching package: 'fgeo.base'
#> The following objects are masked from 'package:fgeo.tool': -#> -#> %||%, check_crucial_names, drop_status, fill_na, flag_if, -#> guess_plotdim, is_duplicated, is_multiple, is_named, name_dfs, -#> pick_dbh_max, pick_dbh_min, pick_dbh_over, pick_dbh_under, -#> pick_status, suffix_match, to_tidy_names
-tree <- tibble(CensusID = c(1, 2), treeID = c(1, 2)) +
tree <- tibble(CensusID = c(1, 2), treeID = c(1, 2)) detect_if_group(tree, "treeID", is_multiple)
#> [1] TRUE
flag_if_group(tree, "treeID", is_multiple)
#> Warning: treeID: Flagged values were detected.
by_censusid <- group_by(tree, CensusID) detect_if_group(by_censusid, "treeID", is_multiple)
#> [1] FALSE
flag_if_group(by_censusid, "treeID", is_multiple)
diff --git a/docs/reference/is_multiple.html b/docs/reference/is_multiple.html index 3092673b..bf3d975a 100644 --- a/docs/reference/is_multiple.html +++ b/docs/reference/is_multiple.html @@ -140,16 +140,12 @@

Value

See also

-

Other functions to check inputs.: check_crucial_names, - flag_if_group

-

Other functions for developers: check_crucial_names, - nms_extract_anycase, +

Other functions to check inputs.: flag_if_group

+

Other functions for developers: nms_extract_anycase, nms_lowercase, nms_restore_newvar, nms_tidy, nms_try_rename, nms

-

Other general predicates: is_named

Other functions for internal use in other fgeo packages: flag_if, - guess_plotdim, is_named, name_dfs, suffix_match

diff --git a/docs/reference/name_dfs.html b/docs/reference/name_dfs.html index 18b6bfcc..faa9e3bc 100644 --- a/docs/reference/name_dfs.html +++ b/docs/reference/name_dfs.html @@ -143,8 +143,7 @@

Value

See also

Other functions for internal use in other fgeo packages: flag_if, - guess_plotdim, is_multiple, - is_named, suffix_match

+ is_multiple, suffix_match

Examples

diff --git a/docs/reference/nms.html b/docs/reference/nms.html index 1eef7fae..38fc0849 100644 --- a/docs/reference/nms.html +++ b/docs/reference/nms.html @@ -160,8 +160,7 @@

Details

See also

-

Other functions for developers: check_crucial_names, - is_multiple, +

Other functions for developers: is_multiple, nms_extract_anycase, nms_lowercase, nms_restore_newvar, nms_tidy, diff --git a/docs/reference/nms_extract_anycase.html b/docs/reference/nms_extract_anycase.html index 6b6d4feb..12cb2d12 100644 --- a/docs/reference/nms_extract_anycase.html +++ b/docs/reference/nms_extract_anycase.html @@ -140,8 +140,8 @@

Value

See also

-

Other functions for developers: check_crucial_names, - is_multiple, nms_lowercase, +

Other functions for developers: is_multiple, + nms_lowercase, nms_restore_newvar, nms_tidy, nms_try_rename, nms

Other functions dealing with names: nms_lowercase, diff --git a/docs/reference/nms_lowercase.html b/docs/reference/nms_lowercase.html index f67ceed8..c6f30f56 100644 --- a/docs/reference/nms_lowercase.html +++ b/docs/reference/nms_lowercase.html @@ -159,8 +159,7 @@

See a

Other functions dealing with names: nms_extract_anycase, nms_restore_newvar, nms_tidy, nms_try_rename, nms

-

Other functions for developers: check_crucial_names, - is_multiple, +

Other functions for developers: is_multiple, nms_extract_anycase, nms_restore_newvar, nms_tidy, nms_try_rename, nms

diff --git a/docs/reference/nms_restore_newvar.html b/docs/reference/nms_restore_newvar.html index dbcd794e..5e708904 100644 --- a/docs/reference/nms_restore_newvar.html +++ b/docs/reference/nms_restore_newvar.html @@ -170,8 +170,7 @@

See a

Other functions dealing with names: nms_extract_anycase, nms_lowercase, nms_tidy, nms_try_rename, nms

-

Other functions for developers: check_crucial_names, - is_multiple, +

Other functions for developers: is_multiple, nms_extract_anycase, nms_lowercase, nms_tidy, nms_try_rename, nms

diff --git a/docs/reference/nms_tidy.html b/docs/reference/nms_tidy.html index eca4922d..19186abe 100644 --- a/docs/reference/nms_tidy.html +++ b/docs/reference/nms_tidy.html @@ -146,8 +146,7 @@

See a nms_lowercase, nms_restore_newvar, nms_try_rename, nms

-

Other functions for developers: check_crucial_names, - is_multiple, +

Other functions for developers: is_multiple, nms_extract_anycase, nms_lowercase, nms_restore_newvar, diff --git a/docs/reference/nms_try_rename.html b/docs/reference/nms_try_rename.html index 8d180a22..b1ff7b94 100644 --- a/docs/reference/nms_try_rename.html +++ b/docs/reference/nms_try_rename.html @@ -147,8 +147,7 @@

See a nms_lowercase, nms_restore_newvar, nms_tidy, nms

-

Other functions for developers: check_crucial_names, - is_multiple, +

Other functions for developers: is_multiple, nms_extract_anycase, nms_lowercase, nms_restore_newvar, nms_tidy, diff --git a/docs/reference/pick_drop.html b/docs/reference/pick_drop.html index 1c0eb2d4..73aaac5d 100644 --- a/docs/reference/pick_drop.html +++ b/docs/reference/pick_drop.html @@ -167,11 +167,10 @@

Value

See also

dplyr::filter(), Extract ([).

-

Other functions for fgeo census and vft.: guess_plotdim

Other functions for fgeo census.: add_status_tree, - add_var, guess_plotdim

+ add_var

Other functions for fgeo vft.: add_status_tree, - add_var, guess_plotdim

+ add_var

Other functions to pick or drop rows of a ForestGEO dataframe: drop_twice_dead, filter_status, pick_main_stem, pick

diff --git a/docs/reference/reexports.html b/docs/reference/reexports.html index 2c1e6c6f..522b0514 100644 --- a/docs/reference/reexports.html +++ b/docs/reference/reexports.html @@ -37,6 +37,8 @@ dplyrfilter, mutate, select, arrange, summarize, summarise, group_by, ungroup, count, add_count" /> + + @@ -130,6 +132,8 @@

Objects exported from other packages

dplyr

filter, mutate, select, arrange, summarize, summarise, group_by, ungroup, count, add_count

+
fgeo.ctfs

check_crucial_names

+
rlang

%||%

tibble

tibble, tribble, as_tibble

diff --git a/docs/reference/round_any.html b/docs/reference/round_any.html new file mode 100644 index 00000000..ff01d901 --- /dev/null +++ b/docs/reference/round_any.html @@ -0,0 +1,149 @@ + + + + + + + + +Round to multiple of any number. Copied from <code>plyr:::round_any.numeric()</code>. — round_any • fgeo.tool + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + +
+ +

Round to multiple of any number. Copied from plyr:::round_any.numeric().

+ +
+ +
round_any(x, accuracy, f = round)
+ + +
+ +
+ + +
+ + + + + + diff --git a/docs/reference/suffix_match.html b/docs/reference/suffix_match.html index d052611e..82077011 100644 --- a/docs/reference/suffix_match.html +++ b/docs/reference/suffix_match.html @@ -151,8 +151,7 @@

See a

Other general functions to edit data in place: fill_na, lookup, to_tidy_names

Other functions for internal use in other fgeo packages: flag_if, - guess_plotdim, is_multiple, - is_named, name_dfs

+ is_multiple, name_dfs

Examples

diff --git a/docs/sitemap.xml b/docs/sitemap.xml index 895bb2b9..78964b60 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -18,9 +18,6 @@ https://forestgeo.github.io/fgeo.tool//reference/as_censuses.html - - https://forestgeo.github.io/fgeo.tool//reference/check_crucial_names.html - https://forestgeo.github.io/fgeo.tool//reference/convert_unit.html @@ -60,15 +57,9 @@ https://forestgeo.github.io/fgeo.tool//reference/flag_if_group.html - - https://forestgeo.github.io/fgeo.tool//reference/guess_plotdim.html - https://forestgeo.github.io/fgeo.tool//reference/is_multiple.html - - https://forestgeo.github.io/fgeo.tool//reference/is_named.html - https://forestgeo.github.io/fgeo.tool//reference/list_csv.html diff --git a/man/add_status_tree.Rd b/man/add_status_tree.Rd index dc0c75ae..012d16e9 100644 --- a/man/add_status_tree.Rd +++ b/man/add_status_tree.Rd @@ -46,10 +46,10 @@ Other functions for ForestGEO data.: \code{\link{add_subquad}}, \code{\link{add_var}} Other functions for fgeo census.: \code{\link{add_var}}, - \code{\link{guess_plotdim}}, \code{\link{pick_drop}} + \code{\link{pick_drop}} Other functions for fgeo vft.: \code{\link{add_var}}, - \code{\link{guess_plotdim}}, \code{\link{pick_drop}} + \code{\link{pick_drop}} } \concept{functions for ForestGEO data.} \concept{functions for fgeo census.} diff --git a/man/add_var.Rd b/man/add_var.Rd index ba03fae8..5f064565 100644 --- a/man/add_var.Rd +++ b/man/add_var.Rd @@ -84,10 +84,10 @@ Other functions for ForestGEO data.: \code{\link{add_status_tree}}, \code{\link{add_subquad}} Other functions for fgeo census.: \code{\link{add_status_tree}}, - \code{\link{guess_plotdim}}, \code{\link{pick_drop}} + \code{\link{pick_drop}} Other functions for fgeo vft.: \code{\link{add_status_tree}}, - \code{\link{guess_plotdim}}, \code{\link{pick_drop}} + \code{\link{pick_drop}} } \concept{functions for ForestGEO data.} \concept{functions for fgeo census.} diff --git a/man/check_crucial_names.Rd b/man/check_crucial_names.Rd deleted file mode 100644 index f07cc93f..00000000 --- a/man/check_crucial_names.Rd +++ /dev/null @@ -1,41 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/check_crucial_names.R -\name{check_crucial_names} -\alias{check_crucial_names} -\title{Check if an object contains specific names.} -\usage{ -check_crucial_names(x, nms) -} -\arguments{ -\item{x}{A named object.} - -\item{nms}{String; names expected to be found in \code{x}.} -} -\value{ -Invisible \code{x}, or an error with informative message. -} -\description{ -Check if an object contains specific names. -} -\examples{ -v <- c(x = 1) -check_crucial_names(v, "x") - -dfm <- data.frame(x = 1) -check_crucial_names(dfm, "x") -} -\seealso{ -Other functions to check inputs.: \code{\link{flag_if_group}}, - \code{\link{is_multiple}} - -Other functions for developers: \code{\link{is_multiple}}, - \code{\link{nms_extract_anycase}}, - \code{\link{nms_lowercase}}, - \code{\link{nms_restore_newvar}}, \code{\link{nms_tidy}}, - \code{\link{nms_try_rename}}, \code{\link{nms}} -} -\concept{exported functions for internal use} -\concept{functions for developers} -\concept{functions to check inputs.} -\concept{general functions to assert} -\keyword{internal} diff --git a/man/flag_if.Rd b/man/flag_if.Rd index 7a8cef1d..364b2475 100644 --- a/man/flag_if.Rd +++ b/man/flag_if.Rd @@ -59,8 +59,7 @@ flag_if(.df, "a", is_multiple) flag_if(.df, "a", is_multiple, message, "Custom") } \seealso{ -Other functions for internal use in other fgeo packages: \code{\link{guess_plotdim}}, - \code{\link{is_multiple}}, \code{\link{is_named}}, +Other functions for internal use in other fgeo packages: \code{\link{is_multiple}}, \code{\link{name_dfs}}, \code{\link{suffix_match}} } \concept{functions for internal use in other fgeo packages} diff --git a/man/flag_if_group.Rd b/man/flag_if_group.Rd index 8bed4eb5..3c402b61 100644 --- a/man/flag_if_group.Rd +++ b/man/flag_if_group.Rd @@ -41,8 +41,7 @@ detect_if_group(by_censusid, "treeID", is_multiple) flag_if_group(by_censusid, "treeID", is_multiple) } \seealso{ -Other functions to check inputs.: \code{\link{check_crucial_names}}, - \code{\link{is_multiple}} +Other functions to check inputs.: \code{\link{is_multiple}} Other functions for developers.: \code{\link{find_data_of_class}}, \code{\link{type_ensure}} diff --git a/man/guess_plotdim.Rd b/man/guess_plotdim.Rd deleted file mode 100644 index 07bb868b..00000000 --- a/man/guess_plotdim.Rd +++ /dev/null @@ -1,46 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/guess_plotdim.R -\name{guess_plotdim} -\alias{guess_plotdim} -\title{Guess plot dimensions.} -\usage{ -guess_plotdim(x, accuracy = 20) -} -\arguments{ -\item{x}{A dataframe; a ForestGEO dataset (census or ViewFullTable).} - -\item{accuracy}{A number giving the accuracy with which to round \code{gx} and -\code{gy}.} -} -\value{ -A numeric vector of length 2. -} -\description{ -Guess plot dimensions. -} -\examples{ -x <- data.frame( - gx = c(0, 300, 979), - gy = c(0, 300, 481) -) -guess_plotdim(x) -} -\seealso{ -Other functions for fgeo census and vft.: \code{\link{pick_drop}} - -Other functions for fgeo census.: \code{\link{add_status_tree}}, - \code{\link{add_var}}, \code{\link{pick_drop}} - -Other functions for fgeo vft.: \code{\link{add_status_tree}}, - \code{\link{add_var}}, \code{\link{pick_drop}} - -Other functions for internal use in other fgeo packages: \code{\link{flag_if}}, - \code{\link{is_multiple}}, \code{\link{is_named}}, - \code{\link{name_dfs}}, \code{\link{suffix_match}} -} -\concept{functions for fgeo census and vft.} -\concept{functions for fgeo census.} -\concept{functions for fgeo vft.} -\concept{functions for internal use in other fgeo packages} -\concept{general functions to find or approximate} -\keyword{internal} diff --git a/man/is_multiple.Rd b/man/is_multiple.Rd index 61912b55..24ddfb1e 100644 --- a/man/is_multiple.Rd +++ b/man/is_multiple.Rd @@ -29,19 +29,14 @@ is_duplicated(c(1, 1)) is_duplicated(c(1, NA)) } \seealso{ -Other functions to check inputs.: \code{\link{check_crucial_names}}, - \code{\link{flag_if_group}} +Other functions to check inputs.: \code{\link{flag_if_group}} -Other functions for developers: \code{\link{check_crucial_names}}, - \code{\link{nms_extract_anycase}}, +Other functions for developers: \code{\link{nms_extract_anycase}}, \code{\link{nms_lowercase}}, \code{\link{nms_restore_newvar}}, \code{\link{nms_tidy}}, \code{\link{nms_try_rename}}, \code{\link{nms}} -Other general predicates: \code{\link{is_named}} - Other functions for internal use in other fgeo packages: \code{\link{flag_if}}, - \code{\link{guess_plotdim}}, \code{\link{is_named}}, \code{\link{name_dfs}}, \code{\link{suffix_match}} } \concept{functions for developers} diff --git a/man/is_named.Rd b/man/is_named.Rd deleted file mode 100644 index 3b6d689c..00000000 --- a/man/is_named.Rd +++ /dev/null @@ -1,38 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/check_crucial_names.R -\name{is_named} -\alias{is_named} -\title{Is named object? (Base-only version of rlang::is_named).} -\usage{ -is_named(x) -} -\arguments{ -\item{x}{An object to test.} -} -\value{ -The scalar \code{TRUE} or \code{FALSE}. -} -\description{ -Is named object? (Base-only version of rlang::is_named). -} -\examples{ -is_named(c(x = 1)) -is_named(c(1)) -is_named(x = 1) - -is_named(data.frame(x = 1)) - -dfm <- data.frame(1) -is_named(dfm) -dfm -} -\seealso{ -Other general predicates: \code{\link{is_multiple}} - -Other functions for internal use in other fgeo packages: \code{\link{flag_if}}, - \code{\link{guess_plotdim}}, \code{\link{is_multiple}}, - \code{\link{name_dfs}}, \code{\link{suffix_match}} -} -\concept{functions for internal use in other fgeo packages} -\concept{general predicates} -\keyword{internal} diff --git a/man/name_dfs.Rd b/man/name_dfs.Rd index b3e646b1..d654b18d 100644 --- a/man/name_dfs.Rd +++ b/man/name_dfs.Rd @@ -29,8 +29,7 @@ name_dfs(dfs2) } \seealso{ Other functions for internal use in other fgeo packages: \code{\link{flag_if}}, - \code{\link{guess_plotdim}}, \code{\link{is_multiple}}, - \code{\link{is_named}}, \code{\link{suffix_match}} + \code{\link{is_multiple}}, \code{\link{suffix_match}} } \concept{functions for internal use in other fgeo packages} \concept{general functions to deal with names} diff --git a/man/nms.Rd b/man/nms.Rd index fcf97a46..3d123188 100644 --- a/man/nms.Rd +++ b/man/nms.Rd @@ -61,8 +61,7 @@ stem <- fgeo.x::stem6 nms_extract_all(stem, "gx", "gy", "PX", "PY") } \seealso{ -Other functions for developers: \code{\link{check_crucial_names}}, - \code{\link{is_multiple}}, +Other functions for developers: \code{\link{is_multiple}}, \code{\link{nms_extract_anycase}}, \code{\link{nms_lowercase}}, \code{\link{nms_restore_newvar}}, \code{\link{nms_tidy}}, diff --git a/man/nms_extract_anycase.Rd b/man/nms_extract_anycase.Rd index 41320d13..4a9ab65b 100644 --- a/man/nms_extract_anycase.Rd +++ b/man/nms_extract_anycase.Rd @@ -25,8 +25,8 @@ dfm <- data.frame(a = 1, B = 1) nms_extract_anycase(dfm, "b") } \seealso{ -Other functions for developers: \code{\link{check_crucial_names}}, - \code{\link{is_multiple}}, \code{\link{nms_lowercase}}, +Other functions for developers: \code{\link{is_multiple}}, + \code{\link{nms_lowercase}}, \code{\link{nms_restore_newvar}}, \code{\link{nms_tidy}}, \code{\link{nms_try_rename}}, \code{\link{nms}} diff --git a/man/nms_lowercase.Rd b/man/nms_lowercase.Rd index 0b32dd7d..a6fcbd06 100644 --- a/man/nms_lowercase.Rd +++ b/man/nms_lowercase.Rd @@ -49,8 +49,7 @@ Other functions dealing with names: \code{\link{nms_extract_anycase}}, \code{\link{nms_restore_newvar}}, \code{\link{nms_tidy}}, \code{\link{nms_try_rename}}, \code{\link{nms}} -Other functions for developers: \code{\link{check_crucial_names}}, - \code{\link{is_multiple}}, +Other functions for developers: \code{\link{is_multiple}}, \code{\link{nms_extract_anycase}}, \code{\link{nms_restore_newvar}}, \code{\link{nms_tidy}}, \code{\link{nms_try_rename}}, \code{\link{nms}} diff --git a/man/nms_restore_newvar.Rd b/man/nms_restore_newvar.Rd index 5638fca2..e72758f2 100644 --- a/man/nms_restore_newvar.Rd +++ b/man/nms_restore_newvar.Rd @@ -61,8 +61,7 @@ Other functions dealing with names: \code{\link{nms_extract_anycase}}, \code{\link{nms_lowercase}}, \code{\link{nms_tidy}}, \code{\link{nms_try_rename}}, \code{\link{nms}} -Other functions for developers: \code{\link{check_crucial_names}}, - \code{\link{is_multiple}}, +Other functions for developers: \code{\link{is_multiple}}, \code{\link{nms_extract_anycase}}, \code{\link{nms_lowercase}}, \code{\link{nms_tidy}}, \code{\link{nms_try_rename}}, \code{\link{nms}} diff --git a/man/nms_tidy.Rd b/man/nms_tidy.Rd index 9dd91cc8..e5a62057 100644 --- a/man/nms_tidy.Rd +++ b/man/nms_tidy.Rd @@ -53,8 +53,7 @@ Other functions dealing with names: \code{\link{nms_extract_anycase}}, \code{\link{nms_restore_newvar}}, \code{\link{nms_try_rename}}, \code{\link{nms}} -Other functions for developers: \code{\link{check_crucial_names}}, - \code{\link{is_multiple}}, +Other functions for developers: \code{\link{is_multiple}}, \code{\link{nms_extract_anycase}}, \code{\link{nms_lowercase}}, \code{\link{nms_restore_newvar}}, diff --git a/man/nms_try_rename.Rd b/man/nms_try_rename.Rd index 5aade5a5..611b36ae 100644 --- a/man/nms_try_rename.Rd +++ b/man/nms_try_rename.Rd @@ -36,8 +36,7 @@ Other functions dealing with names: \code{\link{nms_extract_anycase}}, \code{\link{nms_restore_newvar}}, \code{\link{nms_tidy}}, \code{\link{nms}} -Other functions for developers: \code{\link{check_crucial_names}}, - \code{\link{is_multiple}}, +Other functions for developers: \code{\link{is_multiple}}, \code{\link{nms_extract_anycase}}, \code{\link{nms_lowercase}}, \code{\link{nms_restore_newvar}}, \code{\link{nms_tidy}}, diff --git a/man/pick_drop.Rd b/man/pick_drop.Rd index ce260e29..6258c840 100644 --- a/man/pick_drop.Rd +++ b/man/pick_drop.Rd @@ -78,13 +78,11 @@ pick_dbh_over(drop_status(cns, "D", na.rm = TRUE), 100) \seealso{ \code{dplyr::filter()}, \code{Extract} (\code{[}). -Other functions for fgeo census and vft.: \code{\link{guess_plotdim}} - Other functions for fgeo census.: \code{\link{add_status_tree}}, - \code{\link{add_var}}, \code{\link{guess_plotdim}} + \code{\link{add_var}} Other functions for fgeo vft.: \code{\link{add_status_tree}}, - \code{\link{add_var}}, \code{\link{guess_plotdim}} + \code{\link{add_var}} Other functions to pick or drop rows of a ForestGEO dataframe: \code{\link{drop_twice_dead}}, \code{\link{filter_status}}, diff --git a/man/reexports.Rd b/man/reexports.Rd index 46f997f6..eacb0b68 100644 --- a/man/reexports.Rd +++ b/man/reexports.Rd @@ -3,6 +3,7 @@ \docType{import} \name{reexports} \alias{reexports} +\alias{check_crucial_names} \alias{\%||\%} \alias{filter} \alias{mutate} @@ -34,6 +35,8 @@ below to see their documentation. \describe{ \item{dplyr}{\code{\link[dplyr]{filter}}, \code{\link[dplyr]{mutate}}, \code{\link[dplyr]{select}}, \code{\link[dplyr]{arrange}}, \code{\link[dplyr]{summarize}}, \code{\link[dplyr]{summarise}}, \code{\link[dplyr]{group_by}}, \code{\link[dplyr]{ungroup}}, \code{\link[dplyr]{count}}, \code{\link[dplyr]{add_count}}} + \item{fgeo.ctfs}{\code{\link[fgeo.ctfs]{check_crucial_names}}} + \item{rlang}{\code{\link[rlang]{\%||\%}}} \item{tibble}{\code{\link[tibble]{tibble}}, \code{\link[tibble]{tribble}}, \code{\link[tibble]{as_tibble}}} diff --git a/man/suffix_match.Rd b/man/suffix_match.Rd index ac9f0b6f..6d4dbfe3 100644 --- a/man/suffix_match.Rd +++ b/man/suffix_match.Rd @@ -48,8 +48,7 @@ Other general functions to edit data in place: \code{\link{fill_na}}, \code{\link{lookup}}, \code{\link{to_tidy_names}} Other functions for internal use in other fgeo packages: \code{\link{flag_if}}, - \code{\link{guess_plotdim}}, \code{\link{is_multiple}}, - \code{\link{is_named}}, \code{\link{name_dfs}} + \code{\link{is_multiple}}, \code{\link{name_dfs}} } \concept{functions for internal use in other fgeo packages} \concept{general functions to edit data in place} diff --git a/tests/testthat/test-check_crucial_names.R b/tests/testthat/test-check_crucial_names.R deleted file mode 100644 index 1583f2e3..00000000 --- a/tests/testthat/test-check_crucial_names.R +++ /dev/null @@ -1,8 +0,0 @@ -context("check_crucial_names.R") - -test_that("passes and fails as expected", { - expect_silent(check_crucial_names(c(x = 1), "x")) - expect_error(check_crucial_names(c(x = 1), "y")) - expect_silent(check_crucial_names(data.frame(x = 1), "x")) - expect_error(check_crucial_names(data.frame(x = 1), "y")) -}) diff --git a/tests/testthat/test-guess_plotdim.R b/tests/testthat/test-guess_plotdim.R deleted file mode 100644 index 81441aae..00000000 --- a/tests/testthat/test-guess_plotdim.R +++ /dev/null @@ -1,40 +0,0 @@ -context("test-guess_plotdim.R") - -test_that("outputs expected plotdim and message", { - skip_if_not_installed("fgeo.data") - - x <- data.frame(gx = c(0, 300, 981), gy = c(0, 300, 499)) - expect_equal(guess_plotdim(x), c(1000, 500)) - - x <- data.frame(gx = c(0, 981), gy = c(0, 479)) - expect_equal( - expect_message(guess_plotdim(x), "Guessing"), - c(1000, 480) - ) - - expect_equal(guess_plotdim(fgeo.data::luquillo_stem6_random), c(320, 500)) -}) - - - -context("test-nms_pull_matches") - -test_that("pulls the expected names", { - skip_if_not_installed("fgeo.data") - vft <- fgeo.data::luquillo_stem_random_tiny - expected <- c("gx", "gy") - expect_equal(nms_pull_matches(vft, c("x", "PX", "gx", "gy")), expected) -}) - -test_that("fails with unnamed input", { - expect_error(nms_pull_matches("unnnamed", "x"), "is not TRUE") -}) - - - -context("glue_comma") - -test_that("output the expected string", { - expect_equal(glue_comma(1:3), "1, 2, 3") - expect_equal(glue_pipe(1:3), "1|2|3") -}) From 3b676dce45873d63092997fadd6bab0afe5c0c8e Mon Sep 17 00:00:00 2001 From: maurolepore Date: Thu, 6 Dec 2018 16:45:28 -0500 Subject: [PATCH 7/8] No longer suggest fgeo.habitat. --- DESCRIPTION | 2 -- 1 file changed, 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 09579a31..c728ef88 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -46,7 +46,6 @@ Imports: writexl Suggests: covr, - fgeo.habitat, fgeo.map, knitr, spelling, @@ -55,7 +54,6 @@ VignetteBuilder: knitr Remotes: forestgeo/fgeo.ctfs, - forestgeo/fgeo.habitat, forestgeo/fgeo.map, forestgeo/fgeo.x Encoding: UTF-8 From eb551220744c36484c03d266ae16d33aebd6e48c Mon Sep 17 00:00:00 2001 From: maurolepore Date: Thu, 6 Dec 2018 17:18:23 -0500 Subject: [PATCH 8/8] Refactor to reflect changes in fgeo.map and fgeo.abundance. --- NAMESPACE | 5 +++ R/drop_if_na.R | 2 +- R/pick_plotname.R | 37 +++++++++++++++++++++ R/rename_matches.R | 6 ++-- docs/reference/add_status_tree.html | 2 +- docs/reference/add_var.html | 2 +- docs/reference/drop_twice_dead.html | 2 +- docs/reference/index.html | 6 ++++ docs/sitemap.xml | 6 ++++ man/add_status_tree.Rd | 2 +- man/add_var.Rd | 2 +- man/drop_if_na.Rd | 32 ++++++++++++++++++ man/drop_twice_dead.Rd | 2 +- man/extract_insensitive.Rd | 50 +++++++++++++++++++++++++++++ man/filter_status.Rd | 2 +- man/is_multiple.Rd | 6 ++-- man/name_dfs.Rd | 3 ++ man/nms.Rd | 6 ++-- man/nms_extract_anycase.Rd | 7 ++-- man/nms_lowercase.Rd | 6 ++-- man/nms_restore_newvar.Rd | 6 ++-- man/nms_tidy.Rd | 6 ++-- man/nms_try_rename.Rd | 5 +-- man/pick.Rd | 2 +- man/pick_drop.Rd | 5 +-- man/pick_main_stem.Rd | 2 +- man/pick_plotname.Rd | 35 ++++++++++++++++++++ man/pick_recensus.Rd | 3 +- man/pick_top.Rd | 3 +- man/rename_matches.Rd | 39 ++++++++++++++++++++++ tests/testthat/test-pick_plotname.R | 20 ++++++++++++ 31 files changed, 280 insertions(+), 32 deletions(-) create mode 100644 R/pick_plotname.R create mode 100644 man/drop_if_na.Rd create mode 100644 man/extract_insensitive.Rd create mode 100644 man/pick_plotname.Rd create mode 100644 man/rename_matches.Rd create mode 100644 tests/testthat/test-pick_plotname.R diff --git a/NAMESPACE b/NAMESPACE index f78b13bc..a25e93fe 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -41,8 +41,10 @@ export(count) export(csv_list) export(delim_list) export(detect_if_group) +export(detect_insensitive) export(drop_dead_stem) export(drop_dead_tree) +export(drop_if_na) export(drop_status) export(drop_twice_dead) export(ends_with) @@ -54,6 +56,7 @@ export(everything) export(expr) export(exprs) export(extract_gridsize) +export(extract_insensitive) export(extract_plotdim) export(fgeo_elevation) export(fgeo_habitat) @@ -93,6 +96,7 @@ export(pick_dbh_over) export(pick_dbh_under) export(pick_main_stem) export(pick_main_stemid) +export(pick_plotname) export(pick_recensus) export(pick_status) export(pick_top) @@ -107,6 +111,7 @@ export(read_taxa) export(read_vft) export(read_with) export(recode_subquad) +export(rename_matches) export(sanitize_taxa) export(sanitize_vft) export(select) diff --git a/R/drop_if_na.R b/R/drop_if_na.R index 8bdd92c2..39346b27 100644 --- a/R/drop_if_na.R +++ b/R/drop_if_na.R @@ -11,7 +11,7 @@ #' #' @return A dataframe. #' @keywords internal -#' @noRd +#' @export #' #' @examples #' dfm <- data.frame(a = 1, b = NA) diff --git a/R/pick_plotname.R b/R/pick_plotname.R new file mode 100644 index 00000000..75e88ae2 --- /dev/null +++ b/R/pick_plotname.R @@ -0,0 +1,37 @@ +#' Pick the given or first (alpha sorted) plot from a ViewFullTable. +#' +#' @param vft Dataframe; particularly a ForestGEO ViewFullTable. +#' @param plot_nm Length-1 character vector of the value of `PlotName` (or +#' `plotname`) to pick from `vft`. +#' +#' @family functions for fgeo vft. +#' @family functions to pick or drop rows of a ForestGEO dataframe +#' +#' @return A dataframe. +#' @export +#' +#' @examples +#' vft <- data.frame(PlotName = c("a", "b"), stringsAsFactors = FALSE) +#' pick_plotname(vft) +#' pick_plotname(vft, "b") +pick_plotname <- function(vft, plot_nm = NULL) { + stopifnot(is.data.frame(vft)) + + old <- names(vft) + names(vft) <- tolower(names(vft)) + + check_crucial_names(vft, "plotname") + + plots <- sort(unique(vft$plotname)) + if (is.null(plot_nm)) plot_nm <- plots + + valid_plot <- sort(unique(vft$plotname)) + if (!all(plot_nm %in% valid_plot)) { + stop("plotname = ", plot_nm, " wasn't detected.", call. = FALSE) + } + + message("Using: ", plot_nm[[1]], ".") + out <- vft[vft$plotname == plot_nm[[1]], , drop = FALSE] + stats::setNames(out, old) +} + diff --git a/R/rename_matches.R b/R/rename_matches.R index e91c6969..9773d71c 100644 --- a/R/rename_matches.R +++ b/R/rename_matches.R @@ -9,7 +9,7 @@ #' @return The output is `x` with as many names changed as case-insensitive #' matches there are with the reference. #' @keywords internal -#' @noRd +#' @export #' #' @examples #' ref <- data.frame(COL1 = 1, COL2 = 1) @@ -31,7 +31,7 @@ rename_matches <- function(x, y) { #' #' @return `detect_*` and `extract_*` return a logical vector and a string. #' @keywords internal -#' @noRd +#' @export #' #' @examples #' x <- c("stemid", "n") @@ -70,7 +70,7 @@ extract_insensitive <- function(x, y) { #' @family general functions to assert #' #' @keywords internal -#' @noRd +#' @export #' @rdname extract_insensitive detect_insensitive <- function(x, y) { stopifnot(is.character(x), is.character(y)) diff --git a/docs/reference/add_status_tree.html b/docs/reference/add_status_tree.html index f0a72534..37e5c318 100644 --- a/docs/reference/add_status_tree.html +++ b/docs/reference/add_status_tree.html @@ -149,7 +149,7 @@

See a

Other functions for fgeo census.: add_var, pick_drop

Other functions for fgeo vft.: add_var, - pick_drop

+ pick_drop, pick_plotname

Examples

diff --git a/docs/reference/add_var.html b/docs/reference/add_var.html index 341479dc..d2bd411e 100644 --- a/docs/reference/add_var.html +++ b/docs/reference/add_var.html @@ -181,7 +181,7 @@

See a

Other functions for fgeo census.: add_status_tree, pick_drop

Other functions for fgeo vft.: add_status_tree, - pick_drop

+ pick_drop, pick_plotname

Examples

diff --git a/docs/reference/drop_twice_dead.html b/docs/reference/drop_twice_dead.html index 55e247d1..fb52a5d8 100644 --- a/docs/reference/drop_twice_dead.html +++ b/docs/reference/drop_twice_dead.html @@ -146,7 +146,7 @@

See a

Other functions to pick or drop rows of a ForestGEO dataframe: filter_status, pick_drop, pick_main_stem, - pick

+ pick_plotname, pick

Examples

diff --git a/docs/reference/index.html b/docs/reference/index.html index 72024bc6..3dedaba6 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -259,6 +259,12 @@

Pick the main stem or main stemid(s) of each tree in each census.

+ +

pick_plotname()

+ +

Pick the given or first (alpha sorted) plot from a ViewFullTable.

+ +

pick_recensus()

diff --git a/docs/sitemap.xml b/docs/sitemap.xml index 78964b60..80bd0dd6 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -99,6 +99,9 @@ https://forestgeo.github.io/fgeo.tool//reference/pick_main_stem.html + + https://forestgeo.github.io/fgeo.tool//reference/pick_plotname.html + https://forestgeo.github.io/fgeo.tool//reference/pick_recensus.html @@ -126,6 +129,9 @@ https://forestgeo.github.io/fgeo.tool//reference/reexports.html + + https://forestgeo.github.io/fgeo.tool//reference/rename_matches.html + https://forestgeo.github.io/fgeo.tool//reference/sanitize.html diff --git a/man/add_status_tree.Rd b/man/add_status_tree.Rd index 012d16e9..3aeb7aa7 100644 --- a/man/add_status_tree.Rd +++ b/man/add_status_tree.Rd @@ -49,7 +49,7 @@ Other functions for fgeo census.: \code{\link{add_var}}, \code{\link{pick_drop}} Other functions for fgeo vft.: \code{\link{add_var}}, - \code{\link{pick_drop}} + \code{\link{pick_drop}}, \code{\link{pick_plotname}} } \concept{functions for ForestGEO data.} \concept{functions for fgeo census.} diff --git a/man/add_var.Rd b/man/add_var.Rd index 5f064565..4b0206a4 100644 --- a/man/add_var.Rd +++ b/man/add_var.Rd @@ -87,7 +87,7 @@ Other functions for fgeo census.: \code{\link{add_status_tree}}, \code{\link{pick_drop}} Other functions for fgeo vft.: \code{\link{add_status_tree}}, - \code{\link{pick_drop}} + \code{\link{pick_drop}}, \code{\link{pick_plotname}} } \concept{functions for ForestGEO data.} \concept{functions for fgeo census.} diff --git a/man/drop_if_na.Rd b/man/drop_if_na.Rd new file mode 100644 index 00000000..48a8d0e5 --- /dev/null +++ b/man/drop_if_na.Rd @@ -0,0 +1,32 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/drop_if_na.R +\name{drop_if_na} +\alias{drop_if_na} +\title{Drop if missing values.} +\usage{ +drop_if_na(dfm, x) +} +\arguments{ +\item{dfm}{A dataframe.} + +\item{x}{String giving a column name of \code{dfm}.} +} +\value{ +A dataframe. +} +\description{ +Valuable mostly for its warning. +} +\examples{ +dfm <- data.frame(a = 1, b = NA) +drop_if_na(dfm, "b") +drop_if_na(dfm, "a") +} +\seealso{ +\code{tidyr::drop_na()}. + +Other general functions to pick or drop rows of a dataframe: \code{\link{pick_recensus}}, + \code{\link{pick_top}} +} +\concept{general functions to pick or drop rows of a dataframe} +\keyword{internal} diff --git a/man/drop_twice_dead.Rd b/man/drop_twice_dead.Rd index 20796cf4..6bab5e70 100644 --- a/man/drop_twice_dead.Rd +++ b/man/drop_twice_dead.Rd @@ -53,7 +53,7 @@ drop_twice_dead(vft) \seealso{ Other functions to pick or drop rows of a ForestGEO dataframe: \code{\link{filter_status}}, \code{\link{pick_drop}}, \code{\link{pick_main_stem}}, - \code{\link{pick}} + \code{\link{pick_plotname}}, \code{\link{pick}} } \concept{functions to pick or drop rows of a ForestGEO dataframe} \keyword{internal} diff --git a/man/extract_insensitive.Rd b/man/extract_insensitive.Rd new file mode 100644 index 00000000..c2439d07 --- /dev/null +++ b/man/extract_insensitive.Rd @@ -0,0 +1,50 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/rename_matches.R +\name{extract_insensitive} +\alias{extract_insensitive} +\alias{detect_insensitive} +\title{Detect and extract matching strings -- ignoring case.} +\usage{ +extract_insensitive(x, y) + +detect_insensitive(x, y) +} +\arguments{ +\item{x}{A string to be muted as in \code{y}, it a case insensitive match is +found.} + +\item{y}{A string to use as a reference to match \code{x}.} +} +\value{ +\code{detect_*} and \code{extract_*} return a logical vector and a string. +} +\description{ +Detect and extract matching strings -- ignoring case. + +Return TRUE in position where name of x is in y; FALSE otherwise. +} +\examples{ +x <- c("stemid", "n") +y <- c("StemID", "treeID") +detect_insensitive(x, y) +extract_insensitive(x, y) + +vft <- data.frame(TreeID = 1, Status = 1) +extract_insensitive(tolower(names(vft)), names(vft)) +extract_insensitive(names(vft), tolower(names(vft))) +} +\seealso{ +Other functions for developers: \code{\link{is_multiple}}, + \code{\link{nms_extract_anycase}}, + \code{\link{nms_lowercase}}, + \code{\link{nms_restore_newvar}}, \code{\link{nms_tidy}}, + \code{\link{nms_try_rename}}, \code{\link{nms}}, + \code{\link{rename_matches}} + +Other general functions to deal with names: \code{\link{name_dfs}}, + \code{\link{rename_matches}} +} +\concept{functions for developers} +\concept{general functions to assert} +\concept{general functions to deal with names} +\keyword{internal} diff --git a/man/filter_status.Rd b/man/filter_status.Rd index 6654fbc3..f2b0ccda 100644 --- a/man/filter_status.Rd +++ b/man/filter_status.Rd @@ -153,6 +153,6 @@ table(result$status_tree) Other functions to pick or drop rows of a ForestGEO dataframe: \code{\link{drop_twice_dead}}, \code{\link{pick_drop}}, \code{\link{pick_main_stem}}, - \code{\link{pick}} + \code{\link{pick_plotname}}, \code{\link{pick}} } \concept{functions to pick or drop rows of a ForestGEO dataframe} diff --git a/man/is_multiple.Rd b/man/is_multiple.Rd index 24ddfb1e..577ad7a1 100644 --- a/man/is_multiple.Rd +++ b/man/is_multiple.Rd @@ -31,10 +31,12 @@ is_duplicated(c(1, NA)) \seealso{ Other functions to check inputs.: \code{\link{flag_if_group}} -Other functions for developers: \code{\link{nms_extract_anycase}}, +Other functions for developers: \code{\link{extract_insensitive}}, + \code{\link{nms_extract_anycase}}, \code{\link{nms_lowercase}}, \code{\link{nms_restore_newvar}}, \code{\link{nms_tidy}}, - \code{\link{nms_try_rename}}, \code{\link{nms}} + \code{\link{nms_try_rename}}, \code{\link{nms}}, + \code{\link{rename_matches}} Other functions for internal use in other fgeo packages: \code{\link{flag_if}}, \code{\link{name_dfs}}, \code{\link{suffix_match}} diff --git a/man/name_dfs.Rd b/man/name_dfs.Rd index d654b18d..c2b31c0b 100644 --- a/man/name_dfs.Rd +++ b/man/name_dfs.Rd @@ -28,6 +28,9 @@ dfs2 <- list(data.frame(x = 1), data.frame(x = 1)) name_dfs(dfs2) } \seealso{ +Other general functions to deal with names: \code{\link{extract_insensitive}}, + \code{\link{rename_matches}} + Other functions for internal use in other fgeo packages: \code{\link{flag_if}}, \code{\link{is_multiple}}, \code{\link{suffix_match}} } diff --git a/man/nms.Rd b/man/nms.Rd index 3d123188..4262a530 100644 --- a/man/nms.Rd +++ b/man/nms.Rd @@ -61,11 +61,13 @@ stem <- fgeo.x::stem6 nms_extract_all(stem, "gx", "gy", "PX", "PY") } \seealso{ -Other functions for developers: \code{\link{is_multiple}}, +Other functions for developers: \code{\link{extract_insensitive}}, + \code{\link{is_multiple}}, \code{\link{nms_extract_anycase}}, \code{\link{nms_lowercase}}, \code{\link{nms_restore_newvar}}, \code{\link{nms_tidy}}, - \code{\link{nms_try_rename}} + \code{\link{nms_try_rename}}, + \code{\link{rename_matches}} Other functions dealing with names: \code{\link{nms_extract_anycase}}, \code{\link{nms_lowercase}}, diff --git a/man/nms_extract_anycase.Rd b/man/nms_extract_anycase.Rd index 4a9ab65b..6fca15b5 100644 --- a/man/nms_extract_anycase.Rd +++ b/man/nms_extract_anycase.Rd @@ -25,10 +25,11 @@ dfm <- data.frame(a = 1, B = 1) nms_extract_anycase(dfm, "b") } \seealso{ -Other functions for developers: \code{\link{is_multiple}}, - \code{\link{nms_lowercase}}, +Other functions for developers: \code{\link{extract_insensitive}}, + \code{\link{is_multiple}}, \code{\link{nms_lowercase}}, \code{\link{nms_restore_newvar}}, \code{\link{nms_tidy}}, - \code{\link{nms_try_rename}}, \code{\link{nms}} + \code{\link{nms_try_rename}}, \code{\link{nms}}, + \code{\link{rename_matches}} Other functions dealing with names: \code{\link{nms_lowercase}}, \code{\link{nms_restore_newvar}}, \code{\link{nms_tidy}}, diff --git a/man/nms_lowercase.Rd b/man/nms_lowercase.Rd index a6fcbd06..c9b39065 100644 --- a/man/nms_lowercase.Rd +++ b/man/nms_lowercase.Rd @@ -49,10 +49,12 @@ Other functions dealing with names: \code{\link{nms_extract_anycase}}, \code{\link{nms_restore_newvar}}, \code{\link{nms_tidy}}, \code{\link{nms_try_rename}}, \code{\link{nms}} -Other functions for developers: \code{\link{is_multiple}}, +Other functions for developers: \code{\link{extract_insensitive}}, + \code{\link{is_multiple}}, \code{\link{nms_extract_anycase}}, \code{\link{nms_restore_newvar}}, \code{\link{nms_tidy}}, - \code{\link{nms_try_rename}}, \code{\link{nms}} + \code{\link{nms_try_rename}}, \code{\link{nms}}, + \code{\link{rename_matches}} } \concept{functions dealing with names} \concept{functions for developers} diff --git a/man/nms_restore_newvar.Rd b/man/nms_restore_newvar.Rd index e72758f2..c996a280 100644 --- a/man/nms_restore_newvar.Rd +++ b/man/nms_restore_newvar.Rd @@ -61,10 +61,12 @@ Other functions dealing with names: \code{\link{nms_extract_anycase}}, \code{\link{nms_lowercase}}, \code{\link{nms_tidy}}, \code{\link{nms_try_rename}}, \code{\link{nms}} -Other functions for developers: \code{\link{is_multiple}}, +Other functions for developers: \code{\link{extract_insensitive}}, + \code{\link{is_multiple}}, \code{\link{nms_extract_anycase}}, \code{\link{nms_lowercase}}, \code{\link{nms_tidy}}, - \code{\link{nms_try_rename}}, \code{\link{nms}} + \code{\link{nms_try_rename}}, \code{\link{nms}}, + \code{\link{rename_matches}} } \concept{functions dealing with names} \concept{functions for developers} diff --git a/man/nms_tidy.Rd b/man/nms_tidy.Rd index e5a62057..9168e880 100644 --- a/man/nms_tidy.Rd +++ b/man/nms_tidy.Rd @@ -53,11 +53,13 @@ Other functions dealing with names: \code{\link{nms_extract_anycase}}, \code{\link{nms_restore_newvar}}, \code{\link{nms_try_rename}}, \code{\link{nms}} -Other functions for developers: \code{\link{is_multiple}}, +Other functions for developers: \code{\link{extract_insensitive}}, + \code{\link{is_multiple}}, \code{\link{nms_extract_anycase}}, \code{\link{nms_lowercase}}, \code{\link{nms_restore_newvar}}, - \code{\link{nms_try_rename}}, \code{\link{nms}} + \code{\link{nms_try_rename}}, \code{\link{nms}}, + \code{\link{rename_matches}} } \concept{functions dealing with names} \concept{functions for developers} diff --git a/man/nms_try_rename.Rd b/man/nms_try_rename.Rd index 611b36ae..b2628a26 100644 --- a/man/nms_try_rename.Rd +++ b/man/nms_try_rename.Rd @@ -36,11 +36,12 @@ Other functions dealing with names: \code{\link{nms_extract_anycase}}, \code{\link{nms_restore_newvar}}, \code{\link{nms_tidy}}, \code{\link{nms}} -Other functions for developers: \code{\link{is_multiple}}, +Other functions for developers: \code{\link{extract_insensitive}}, + \code{\link{is_multiple}}, \code{\link{nms_extract_anycase}}, \code{\link{nms_lowercase}}, \code{\link{nms_restore_newvar}}, \code{\link{nms_tidy}}, - \code{\link{nms}} + \code{\link{nms}}, \code{\link{rename_matches}} } \concept{functions dealing with names} \concept{functions for developers} diff --git a/man/pick.Rd b/man/pick.Rd index b8d0c7d2..c32f390e 100644 --- a/man/pick.Rd +++ b/man/pick.Rd @@ -43,6 +43,6 @@ censuses \%>\% \seealso{ Other functions to pick or drop rows of a ForestGEO dataframe: \code{\link{drop_twice_dead}}, \code{\link{filter_status}}, \code{\link{pick_drop}}, - \code{\link{pick_main_stem}} + \code{\link{pick_main_stem}}, \code{\link{pick_plotname}} } \concept{functions to pick or drop rows of a ForestGEO dataframe} diff --git a/man/pick_drop.Rd b/man/pick_drop.Rd index 6258c840..d8b79c25 100644 --- a/man/pick_drop.Rd +++ b/man/pick_drop.Rd @@ -82,11 +82,12 @@ Other functions for fgeo census.: \code{\link{add_status_tree}}, \code{\link{add_var}} Other functions for fgeo vft.: \code{\link{add_status_tree}}, - \code{\link{add_var}} + \code{\link{add_var}}, \code{\link{pick_plotname}} Other functions to pick or drop rows of a ForestGEO dataframe: \code{\link{drop_twice_dead}}, \code{\link{filter_status}}, - \code{\link{pick_main_stem}}, \code{\link{pick}} + \code{\link{pick_main_stem}}, + \code{\link{pick_plotname}}, \code{\link{pick}} } \concept{functions for fgeo census and vft.} \concept{functions for fgeo census.} diff --git a/man/pick_main_stem.Rd b/man/pick_main_stem.Rd index 4fe8ae61..00b58a97 100644 --- a/man/pick_main_stem.Rd +++ b/man/pick_main_stem.Rd @@ -66,6 +66,6 @@ pick_main_stemid(census) \seealso{ Other functions to pick or drop rows of a ForestGEO dataframe: \code{\link{drop_twice_dead}}, \code{\link{filter_status}}, \code{\link{pick_drop}}, - \code{\link{pick}} + \code{\link{pick_plotname}}, \code{\link{pick}} } \concept{functions to pick or drop rows of a ForestGEO dataframe} diff --git a/man/pick_plotname.Rd b/man/pick_plotname.Rd new file mode 100644 index 00000000..fb4261ca --- /dev/null +++ b/man/pick_plotname.Rd @@ -0,0 +1,35 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/pick_plotname.R +\name{pick_plotname} +\alias{pick_plotname} +\title{Pick the given or first (alpha sorted) plot from a ViewFullTable.} +\usage{ +pick_plotname(vft, plot_nm = NULL) +} +\arguments{ +\item{vft}{Dataframe; particularly a ForestGEO ViewFullTable.} + +\item{plot_nm}{Length-1 character vector of the value of \code{PlotName} (or +\code{plotname}) to pick from \code{vft}.} +} +\value{ +A dataframe. +} +\description{ +Pick the given or first (alpha sorted) plot from a ViewFullTable. +} +\examples{ +vft <- data.frame(PlotName = c("a", "b"), stringsAsFactors = FALSE) +pick_plotname(vft) +pick_plotname(vft, "b") +} +\seealso{ +Other functions for fgeo vft.: \code{\link{add_status_tree}}, + \code{\link{add_var}}, \code{\link{pick_drop}} + +Other functions to pick or drop rows of a ForestGEO dataframe: \code{\link{drop_twice_dead}}, + \code{\link{filter_status}}, \code{\link{pick_drop}}, + \code{\link{pick_main_stem}}, \code{\link{pick}} +} +\concept{functions for fgeo vft.} +\concept{functions to pick or drop rows of a ForestGEO dataframe} diff --git a/man/pick_recensus.Rd b/man/pick_recensus.Rd index 875b78b9..ab78830a 100644 --- a/man/pick_recensus.Rd +++ b/man/pick_recensus.Rd @@ -81,6 +81,7 @@ pick_recensus(x, y2, by = c("unique_stem" = "unq_stem")) dplyr::anti_join(x, y2, by = c("unique_stem" = "unq_stem")) } \seealso{ -Other general functions to pick or drop rows of a dataframe: \code{\link{pick_top}} +Other general functions to pick or drop rows of a dataframe: \code{\link{drop_if_na}}, + \code{\link{pick_top}} } \concept{general functions to pick or drop rows of a dataframe} diff --git a/man/pick_top.Rd b/man/pick_top.Rd index 622173cd..58fb4d87 100644 --- a/man/pick_top.Rd +++ b/man/pick_top.Rd @@ -51,6 +51,7 @@ pick_top(df, y, n = -2) \seealso{ \link[dplyr:pull]{dplyr::pull}, \link[dplyr:top_n]{dplyr::top_n}, \code{\link[utils:head]{utils::head()}}, \code{\link[utils:tail]{utils::tail()}}. -Other general functions to pick or drop rows of a dataframe: \code{\link{pick_recensus}} +Other general functions to pick or drop rows of a dataframe: \code{\link{drop_if_na}}, + \code{\link{pick_recensus}} } \concept{general functions to pick or drop rows of a dataframe} diff --git a/man/rename_matches.Rd b/man/rename_matches.Rd new file mode 100644 index 00000000..8539cd55 --- /dev/null +++ b/man/rename_matches.Rd @@ -0,0 +1,39 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/rename_matches.R +\name{rename_matches} +\alias{rename_matches} +\title{Rename an object based on case-insensitive match of the names of a reference.} +\usage{ +rename_matches(x, y) +} +\arguments{ +\item{x}{x object which names to restored if they match the reference.} + +\item{y}{Named object to use as reference.} +} +\value{ +The output is \code{x} with as many names changed as case-insensitive +matches there are with the reference. +} +\description{ +Rename an object based on case-insensitive match of the names of a reference. +} +\examples{ +ref <- data.frame(COL1 = 1, COL2 = 1) +x <- data.frame(col1 = 5, col2 = 1, n = 5) +rename_matches(x, ref) +} +\seealso{ +Other functions for developers: \code{\link{extract_insensitive}}, + \code{\link{is_multiple}}, + \code{\link{nms_extract_anycase}}, + \code{\link{nms_lowercase}}, + \code{\link{nms_restore_newvar}}, \code{\link{nms_tidy}}, + \code{\link{nms_try_rename}}, \code{\link{nms}} + +Other general functions to deal with names: \code{\link{extract_insensitive}}, + \code{\link{name_dfs}} +} +\concept{functions for developers} +\concept{general functions to deal with names} +\keyword{internal} diff --git a/tests/testthat/test-pick_plotname.R b/tests/testthat/test-pick_plotname.R new file mode 100644 index 00000000..aef2d0d0 --- /dev/null +++ b/tests/testthat/test-pick_plotname.R @@ -0,0 +1,20 @@ +context("pick_plotname") + +vft <- data.frame(PlotName = c("a", "b"), stringsAsFactors = FALSE) + +test_that("errs as expected", { + expect_error(pick_plotname("not dfm", "a"), "not TRUE") + expect_error(pick_plotname(vft, "bad"), "wasn't detected") + expect_message(pick_plotname(vft), "Using") +}) + +test_that("has correct structure", { + out <- suppressMessages(suppressWarnings(pick_plotname(vft, "a"))) + expect_is(out, "data.frame") + expect_equal(nrow(out), 1) + expect_equal(names(out), "PlotName") + expect_equal(out[[1]], "a") + + out <- suppressMessages(suppressWarnings(pick_plotname(vft, "b"))) + expect_equal(out[[1]], "b") +})