From 329b848eb68806759d2b63303f6592d5fe0418f9 Mon Sep 17 00:00:00 2001
From: maurolepore Other functions for ForestGEO data.: Other functions for fgeo census.: See a
add_subquad
,
add_var
add_var
,
- pick_drop
guess_plotdim
, pick_drop
Other functions for fgeo vft.: add_var
,
- pick_drop
guess_plotdim
, pick_drop
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
R/check_crucial_names.R
+ check_crucial_names.Rd
Check if an object contains specific names.
+ +check_crucial_names(x, nms)+ +
x | +A named object. |
+
---|---|
nms | +String; names expected to be found in |
+
Invisible x
, or an error with informative message.
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
+v <- c(x = 1) +check_crucial_names(v, "x") + +dfm <- data.frame(x = 1) +check_crucial_names(dfm, "x")
Other general functions to edit data in place: lookup
,
- to_tidy_names
suffix_match
, to_tidy_names
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, ...)+ +
.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. |
+
msg | +String. An optional custom message. |
+
A condition (and .data
invisibly).
Other functions for internal use in other fgeo packages: guess_plotdim
,
+ is_named
, name_dfs
,
+ suffix_match
+#> 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')"#> 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')"#> Error in UseMethod("flag_if"): no applicable method for 'flag_if' applied to an object of class "c('double', 'numeric')"#> 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"
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()
.
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
library(fgeo.base)#> #>#>#> -#> -#>+#>+#> +#>#> [1] TRUEflag_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 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +++ + + + + + 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 @@ + + + + + + + + ++ + + + + +++ + ++ + ++ ++ ++ +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
++#>#> [1] 980 500Is named object? (Base-only version of rlang::is_named). — is_named • fgeo.tool + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +++ + + + + + 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 @@+ + + + + +++ + +++ +++ +Is named object? (Base-only version of rlang::is_named).
+ Source:R/check_crucial_names.R
++is_named.Rd
+ ++ +Is named object? (Base-only version of rlang::is_named).
+ +is_named(x)+ +Arguments
++
+ ++ + +x ++ An object to test.
Value
+ +The scalar
+ +TRUE
orFALSE
.See also
+ ++ + +Other functions for internal use in other fgeo packages:
flag_if
, +guess_plotdim
,name_dfs
, +suffix_match
Examples
++#> [1] TRUE#> [1] FALSEis_named(x = 1)#> [1] FALSE#> [1] TRUE#> [1] TRUEdfm#> X1 +#> 1 1See a
+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 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +++ + + + + + 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 @@+ + + + + +++ + ++ + ++ ++ ++ +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
++#> $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 +#>#> $df1 +#> x name +#> 1 1 df1 +#> +#> $df2 +#> x name +#> 1 1 df2 +#>Details
See also
-Other functions for developers:
nms_extract_anycase
, +Other functions for developers:
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 @@check_crucial_names
, +nms_extract_anycase
,nms_lowercase
,nms_restore_newvar
,nms_tidy
,nms_try_rename
Value
See also
-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 @@ + + + + + + + + +Other functions for developers:
nms_lowercase
, +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 @@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
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 @@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
See a
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 @@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
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
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
Default value for + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +NULL
. — op-null-default • fgeo.tool++ + + + + + 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 @@+ + + + + +++ + ++ + ++ ++ ++ +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 fromrlang::
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] 1NULL %||% 2#> [1] 2Value
See also
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 @@ + + + + + + + + ++
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
Suffix a strings where a vector exactly matches one specific string. — suffix_match • fgeo.tool + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +++ + + + + + 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 @@+ + + + + +++ + +++ +++ +Suffix a strings where a vector exactly matches one specific string.
+ Source:R/suffix_match.R
++suffix_match.Rd
+ ++ +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 02See a +
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 +@@ -51,9 +54,18 @@ https://forestgeo.github.io/fgeo.tool//reference/convert_unit.html + 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 +@@ -63,6 +75,9 @@ https://forestgeo.github.io/fgeo.tool//reference/list_csv.html + https://forestgeo.github.io/fgeo.tool//reference/lookup.html + https://forestgeo.github.io/fgeo.tool//reference/name_dfs.html +@@ -123,6 +138,9 @@ https://forestgeo.github.io/fgeo.tool//reference/nms.html + https://forestgeo.github.io/fgeo.tool//reference/standardize_at.html + https://forestgeo.github.io/fgeo.tool//reference/suffix_match.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 https://forestgeo.github.io/fgeo.tool//reference/suffix_tags_beyond_edge.html 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 zcmZ`-2UL?w(?$@Gi1cC 9kYd~Og zKTiw@jBqA7dl1|}U}I-D3=t$nRxkzqy+HQ21r$AswigCZ`l${^5bz}OkO-3dz8q|d zArid3(B%E3|Fa)O;g>rMFnBkT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LW~nMA?#P_s(~M;c09Ed+vqzxwlnrcrShU@OA{ P>oeN4P2g|hPw_^W|vLI2~#??e2v`=dyAI)l?ydQ{J^9&kvpj7ZO(9G+(FjP z>0s$E_wAQJ$|_6B3TsZS5sK)^`y#5CZ(G4n7Wwv^+avptn*y)3JB5Qpz^V?rzK6PF z*E37nRnL91JLr8o;nVDU2!n7c%6zrkIvlCG kA543+riAe}? zMq(NFts%pQU8-*N{^~i^jNrw+lUwU6B?(5k!8ALOn+LzqaVUjT|02&nS{a&na@zol zC-*Way!G!93X50A6S2Pp05B5k>WU%vFDMNPTadI27>C7s6G8U>puyi+_Ai?IWBczM z{O{U`A|#Xi3(hz)`z7=8?}z@-(ZP6J#gMRQXEF`{Wz%Oe>7uqLjV8( 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
, +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 @@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
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
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
+flag_if(.df, "b", is_multiple) +flag_if(.df, "a", is_multiple)#> 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")#>#> Error in UseMethod("flag_if"): no applicable method for 'flag_if' applied to an object of class "c('double', 'numeric')"#> 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"