Skip to content

Commit

Permalink
Merge pull request #18 from ccsarapas/dev
Browse files Browse the repository at this point in the history
release lighthouse 0.7.2
  • Loading branch information
ccsarapas authored Jul 17, 2024
2 parents fa18520 + 20b29bc commit 4db9e66
Show file tree
Hide file tree
Showing 30 changed files with 449 additions and 181 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: lighthouse
Title: Utility Functions for Lighthouse Institute Projects
Version: 0.7.1
Version: 0.7.2
Authors@R:
person("Casey", "Sarapas",
email = "[email protected]",
Expand Down
5 changes: 4 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,17 @@ export(pct_valid)
export(percent)
export(pivot_wider_alt)
export(pmax_across)
export(pmean)
export(pmean_across)
export(pmin_across)
export(print_all)
export(print_n)
export(psum)
export(psum_across)
export(rbool)
export(reorder_dendro_by_label)
export(rev_rows)
export(reverse_key)
export(row_sums_across)
export(row_sums_spss)
export(safe_max)
export(safe_min)
Expand Down
47 changes: 39 additions & 8 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,38 @@
# lighthouse 0.7.1
# lighthouse 0.7.2

## Bug fixes

* `open_file()`, `open_location()`, and `in_excel()` now work on MacOS (fixes #17).

## Changes to row-wise aggregation functions

* Added `psum()` and `pmean()`:

* These compute "parallel" or row-wise sums or means, analogous to `base::pmax()` and `base::pmin()`.

* `psum()` deprecates `row_sums_spss()`. (`psum()` is a clearer and more consistent name, as its behavior is closer to that of `pmin()` / `pmax()` than `rowSums()`.) Note that `psum()` has `na.rm = FALSE` by default whereas `row_sums_spss()` defaulted to `na.rm = TRUE`.

* Added `psum_across()` and `pmean_across()`:

* These are implementations of `psum()` and `pmean()` that take tidyselect expressions, complementing `pmin_across()` and `pmax_across()`.

* `psum_across()` replaces `row_sums_across()`, which was introduced in 0.7.0 but is now removed (closes #16).

* All `p*_across()` functions now accept tidyselect expressions via `...` rather than `cols`. This makes it easier to include multiple tidyselect expressions, e.g., `psum_across(var1:var9, starts_with("An"))`.

* Updated documentation for `psum()`, `psum_across()`, and friends. In particular, see the Details section of `psum_across()`, which contrasts use cases for `psum()` vs. `psum_across()`.

## Lifecycle changes

* `coerce_na_range()` is deprecated in favor of `na_if_range()`.

## Other changes

## Bug fix & enhancement
* Added a hex logo!

# lighthouse 0.7.1

## Bug fix
* `strftime_no_lead()` now removes leading zeroes only from specified components of date-times (fixes #14).

# lighthouse 0.7.0
Expand Down Expand Up @@ -95,12 +126,6 @@

* Removed Inauguration Day from `holidays_us`.

## Other changes

* In `asterisks()`, changed the default for `include_key` from `TRUE` to `FALSE`.

* `percent()` and `comma()` re-exported from scales (#11).

## Lifecycle changes

* `rbool()` has been *un*-deprecated. It was previously deprecated in favor of `purrr::rbernoulli()`, but `purrr::rbernoulli()` has since been deprecated itself.
Expand All @@ -115,6 +140,12 @@

* `se()` renamed to `se_mean()`; the old name is deprecated.

## Other changes

* In `asterisks()`, changed the default for `include_key` from `TRUE` to `FALSE`.

* `percent()` and `comma()` re-exported from scales (#11).

# lighthouse 0.6.0

## New functions
Expand Down
24 changes: 21 additions & 3 deletions R/deprecated.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,18 @@ get_col_types <- function(.data) {


#' Replicate SPSS SUM() function - DEPRECATED
#'
#' @description
#' Deprecated in lighthouse 0.7.0 in favor of [row_sums_across()], which provides more
#' information and features and is more stable.
#' Deprecated in lighthouse 0.7.2 in favor of [`psum()`].
#'
#' Sums across columns a la SPSS: `NA`s are counted as 0s, but if ALL variables
#' are `NA`, then result is `NA`.
#'
#' @export
row_sums_spss <- function(...) {
.Deprecated("row_sums_across", old = "row_sums_spss")
.Deprecated(
msg = "`row_sums_spss()` is deprecated. Use `psum()` with `na.rm = TRUE` instead."
)
sums <- tibble::tibble(...) %>%
dplyr::mutate(
out = dplyr::if_else(
Expand Down Expand Up @@ -177,3 +179,19 @@ se <- function(x, na.rm = FALSE) {
.Deprecated(msg = "`se()` is deprecated. Use `se_mean()` or `se_prop()` instead.")
se_mean(x, na.rm)
}


#' Set NA values based on numbers stored as strings - DEPRECATED
#'
#' @description
#' Deprecated in lighthouse 0.7.2 favor of [`na_if_range()`], which
#' this now calls.
#'
#' Changes values coercible to numeric in range `range_min`:`range_max` to `NA`.
#' Useful for imported SPSS files.
#'
#' @export
coerce_na_range <- function(x, range_min = -Inf, range_max = -1) {
.Deprecated(new = "na_if_range()", old = "coerce_na_range()")
na_if_range(x, range_min, range_max)
}
13 changes: 6 additions & 7 deletions R/display.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,25 @@
#' Saves dataframe as .csv in R temp directory, then opens in Excel. The .csv
#' will have a randomly-generated name unless otherwise specified in `name`.
#'
#' @param df The dataframe to open in Excel.
#' @param name (Optional) The name to use for the .csv file. If not provided, a random name will be generated.
#' @param na (Optional) The string to use for missing values in the .csv file. Defaults to an empty string.
#' @param df a data frame or data frame extension (e.g., a tibble).
#' @param name a string: the name to use for the .csv file. If `NULL`, a random name will be generated.
#' @param na string to use for missing values in the .csv file.
#'
#' @export
in_excel <- function(df, name, na = "") {
in_excel <- function(df, name = NULL, na = "") {
csv_dir <- file.path(tempdir(), "csv")
if (!dir.exists(csv_dir)) {
dir.create(csv_dir)
}
if (missing(name)) {
if (is.null(name)) {
csv_path <- tempfile(tmpdir = csv_dir, fileext = ".csv")
} else {
csv_path <- file.path(csv_dir, paste0(name, ".csv"))
}
readr::write_excel_csv(df, csv_path, na = na)
shell.exec(csv_path)
open_file(csv_path)
}


#' Print specified number of tibble rows
#'
#' @export
Expand Down
Loading

0 comments on commit 4db9e66

Please sign in to comment.