Skip to content

Commit fa38611

Browse files
committed
Replace lost_tags_action.R with lost_labels_action.R
Updating to the **datatagr** package for handling the lost action. Also reexporting for ease of use for the user.
1 parent cba7148 commit fa38611

File tree

10 files changed

+50
-156
lines changed

10 files changed

+50
-156
lines changed

R/linelist-package.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
#'
2222
#' * [labels_df()]: to get a `data.frame` of all tagged variables
2323
#'
24-
#' * [lost_tags_action()]: to change the behaviour of actions where tagged
24+
#' * [lost_labels_action()]: to change the behaviour of actions where tagged
2525
#' variables are lost (e.g. removing columns storing tagged variables) to
2626
#' issue warnings, errors, or do nothing
2727
#'
28-
#' * [get_lost_tags_action()]: to check the current behaviour of actions where
28+
#' * [get_lost_labels_action()]: to check the current behaviour of actions where
2929
#' tagged variables are lost
3030
#'
3131
#' @section Dedicated methods:
@@ -72,15 +72,15 @@
7272
#' x[, 2:5]
7373
#'
7474
#' ## to silence warnings when taggs are dropped
75-
#' lost_tags_action("none")
75+
#' lost_labels_action("none")
7676
#' x[, 2:5]
7777
#'
7878
#' ## to trigger errors when taggs are dropped
79-
#' # lost_tags_action("error")
79+
#' # lost_labels_action("error")
8080
#' # x[, 2:5]
8181
#'
8282
#' ## reset default behaviour
83-
#' lost_tags_action()
83+
#' lost_labels_action()
8484
#'
8585
#'
8686
#' # using tidyverse style

R/lost_labels_action.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#' @importFrom datatagr lost_labels_action
2+
#' @export
3+
datatagr::lost_labels_action
4+
5+
#' @importFrom datatagr get_lost_labels_action
6+
#' @export
7+
datatagr::get_lost_labels_action

R/lost_tags_action.R

Lines changed: 0 additions & 79 deletions
This file was deleted.

R/square_bracket.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#' The `[]` and `[[]]` operators for `linelist` objects behaves like for regular
44
#' `data.frame` or `tibble`, but check that tagged variables are not lost, and
55
#' takes the appropriate action if this is the case (warning, error, or ignore,
6-
#' depending on the general option set via [lost_tags_action()]) .
6+
#' depending on the general option set via [lost_labels_action()]) .
77
#'
88
#' @inheritParams base::Extract
99
#' @param x a `linelist` object
@@ -19,9 +19,9 @@
1919
#' @return If no drop is happening, a `linelist`. Otherwise an atomic vector.
2020
#'
2121
#' @seealso
22-
#' * [lost_tags_action()] to set the behaviour to adopt when tags are
22+
#' * [lost_labels_action()] to set the behaviour to adopt when tags are
2323
#' lost through subsetting; default is to issue a warning
24-
#' * [get_lost_tags_action()] to check the current the behaviour
24+
#' * [get_lost_labels_action()] to check the current the behaviour
2525
#'
2626
#' @export
2727
#'
@@ -70,7 +70,7 @@
7070
# args, in case we wanted to use them; so declassing the object instead using
7171
# the datatagr::drop_datatagr() function
7272

73-
lost_action <- get_lost_tags_action()
73+
lost_action <- get_lost_labels_action()
7474

7575
# Handle the corner case where only 1 arg is passed (x[i]) to subset by column
7676
n_args <- nargs() - !missing(drop)
@@ -105,7 +105,7 @@
105105
#' @rdname sub_linelist
106106

107107
`[<-.linelist` <- function(x, i, j, value) {
108-
lost_action <- get_lost_tags_action()
108+
lost_action <- get_lost_labels_action()
109109
out <- NextMethod()
110110
old_tags <- labels(x, show_null = TRUE)
111111
out <- restore_tags(out, old_tags, lost_action)
@@ -117,7 +117,7 @@
117117
#' @rdname sub_linelist
118118

119119
`[[<-.linelist` <- function(x, i, j, value) {
120-
lost_action <- get_lost_tags_action()
120+
lost_action <- get_lost_labels_action()
121121
out <- NextMethod()
122122
old_tags <- labels(x, show_null = TRUE)
123123
out <- restore_tags(out, old_tags, lost_action)
@@ -128,7 +128,7 @@
128128
#'
129129
#' @rdname sub_linelist
130130
`$<-.linelist` <- function(x, name, value) {
131-
lost_action <- get_lost_tags_action()
131+
lost_action <- get_lost_labels_action()
132132
out <- NextMethod()
133133
old_tags <- labels(x, show_null = TRUE)
134134
out <- restore_tags(out, old_tags, lost_action)

R/zzz.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
.onLoad <- function(libname, pkgname) {
2-
lost_tags_action(Sys.getenv("LINELIST_LOST_ACTION", "warning"), quiet = TRUE)
2+
lost_labels_action(Sys.getenv("LINELIST_LOST_ACTION", "warning"), quiet = TRUE)
33
}

tests/testthat/test-lost_tags_action.R

Lines changed: 0 additions & 34 deletions
This file was deleted.

tests/testthat/test-square_bracket.R

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
test_that("tests for [ operator", {
22
x <- make_linelist(cars, id = "speed", age = "dist")
3-
on.exit(lost_tags_action())
3+
on.exit(lost_labels_action())
44

55
# errors
6-
lost_tags_action("warning", quiet = TRUE)
6+
lost_labels_action("warning", quiet = TRUE)
77
msg <- "The following tags have lost their variable:\n age:dist"
88
expect_warning(x[, 1], msg)
99

10-
lost_tags_action("error", quiet = TRUE)
10+
lost_labels_action("error", quiet = TRUE)
1111
msg <- "The following tags have lost their variable:\n age:dist"
1212
expect_error(x[, 1], msg)
1313

14-
lost_tags_action("warning", quiet = TRUE)
14+
lost_labels_action("warning", quiet = TRUE)
1515
msg <- "The following tags have lost their variable:\n id:speed, age:dist"
1616
expect_warning(x[, NULL], msg)
1717

@@ -21,7 +21,7 @@ test_that("tests for [ operator", {
2121
expect_null(ncol(x[, 1, drop = TRUE]))
2222
expect_identical(x[, 1, drop = TRUE], cars[, 1])
2323

24-
lost_tags_action("none", quiet = TRUE)
24+
lost_labels_action("none", quiet = TRUE)
2525
expect_identical(x[, 1], make_linelist(cars[, 1, drop = FALSE], id = "speed"))
2626

2727
# [ behaves exactly as in the simple data.frame case, including when subset
@@ -53,15 +53,15 @@ test_that("tests for [ operator", {
5353
})
5454

5555
test_that("tests for [<- operator", {
56-
on.exit(lost_tags_action())
56+
on.exit(lost_labels_action())
5757

5858
# errors
59-
lost_tags_action("warning", quiet = TRUE)
59+
lost_labels_action("warning", quiet = TRUE)
6060
x <- make_linelist(cars, id = "speed", age = "dist")
6161
msg <- "The following tags have lost their variable:\n id:speed"
6262
expect_warning(x[, 1] <- NULL, msg)
6363

64-
lost_tags_action("error", quiet = TRUE)
64+
lost_labels_action("error", quiet = TRUE)
6565
x <- make_linelist(cars, id = "speed", age = "dist")
6666
msg <- "The following tags have lost their variable:\n id:speed"
6767
expect_error(x[, 1] <- NULL, msg)
@@ -70,22 +70,22 @@ test_that("tests for [<- operator", {
7070
x[1:3, 1] <- 1L
7171
expect_identical(x$speed[1:3], rep(1, 3))
7272

73-
lost_tags_action("none", quiet = TRUE)
73+
lost_labels_action("none", quiet = TRUE)
7474
x <- make_linelist(cars, id = "speed", age = "dist")
7575
x[, 1:2] <- NULL
7676
expect_identical(ncol(x), 0L)
7777
})
7878

7979
test_that("tests for [[<- operator", {
80-
on.exit(lost_tags_action())
80+
on.exit(lost_labels_action())
8181

8282
# errors
83-
lost_tags_action("warning", quiet = TRUE)
83+
lost_labels_action("warning", quiet = TRUE)
8484
x <- make_linelist(cars, id = "speed", age = "dist")
8585
msg <- "The following tags have lost their variable:\n id:speed"
8686
expect_warning(x[[1]] <- NULL, msg)
8787

88-
lost_tags_action("error", quiet = TRUE)
88+
lost_labels_action("error", quiet = TRUE)
8989
x <- make_linelist(cars, id = "speed", age = "dist")
9090
msg <- "The following tags have lost their variable:\n id:speed"
9191
expect_error(x[[1]] <- NULL, msg)
@@ -94,28 +94,28 @@ test_that("tests for [[<- operator", {
9494
x[[1]] <- 1L
9595
expect_identical(x$speed, rep(1L, nrow(x)))
9696

97-
lost_tags_action("none", quiet = TRUE)
97+
lost_labels_action("none", quiet = TRUE)
9898
x <- make_linelist(cars, id = "speed", age = "dist")
9999
x[[2]] <- NULL
100100
x[[1]] <- NULL
101101
expect_identical(ncol(x), 0L)
102102
})
103103

104104
test_that("$<- operator detects tag loss", {
105-
on.exit(lost_tags_action())
105+
on.exit(lost_labels_action())
106106

107107
# errors
108-
lost_tags_action("warning", quiet = TRUE)
108+
lost_labels_action("warning", quiet = TRUE)
109109
x <- make_linelist(cars, id = "speed", age = "dist")
110110
msg <- "The following tags have lost their variable:\n id:speed"
111111
expect_warning(x$speed <- NULL, msg)
112112

113-
lost_tags_action("error", quiet = TRUE)
113+
lost_labels_action("error", quiet = TRUE)
114114
x <- make_linelist(cars, id = "speed", age = "dist")
115115
msg <- "The following tags have lost their variable:\n id:speed"
116116
expect_error(x$speed <- NULL, msg)
117117

118-
lost_tags_action("none", quiet = TRUE)
118+
lost_labels_action("none", quiet = TRUE)
119119
x <- make_linelist(cars, id = "speed", age = "dist")
120120
x$speed <- NULL
121121
x$dist <- NULL

tests/testthat/test-zzz.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ test_that("tests for zzz", {
55
res <- callr::r(
66
function() {
77
library(linelist)
8-
get_lost_tags_action()
8+
get_lost_labels_action()
99
}
1010
)
1111
expect_identical(res, "warning")
1212

1313
})
1414

15-
test_that("Environment variable is used for initial `lost_tags_action`", {
15+
test_that("Environment variable is used for initial `lost_labels_action`", {
1616
# We need to use callr to avoid conflicts with other tests
1717
res <- callr::r(
1818
function() {
1919
library(linelist)
20-
get_lost_tags_action()
20+
get_lost_labels_action()
2121
},
2222
env = c(LINELIST_LOST_ACTION = "error")
2323
)

vignettes/compat-dplyr.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ x %>%
9191
During operations on columns, linelist will:
9292

9393
- stay invisible and conserve tags if no tagged column is affected by the operation
94-
- trigger `lost_tags_action()` if tagged columns are affected by the operation
94+
- trigger `lost_labels_action()` if tagged columns are affected by the operation
9595

9696
### `dplyr::mutate()` ✓ (partial)
9797

0 commit comments

Comments
 (0)