quanteda / quanteda.tidy
Showing 3 of 11 files from the diff.
Newly tracked file
R/relocate.R created.
Newly tracked file
R/rename.R created.
Other files ignored by Codecov

@@ -0,0 +1,25 @@
Loading
1 +
#' @name relocate
2 +
#' @rdname dplyr_single
3 +
#' @importFrom dplyr relocate
4 +
#' @export
5 +
NULL
6 +
7 +
#' Change column order of document variables
8 +
#'
9 +
#' Use `relocate()` to change the column positions of document variables, using
10 +
#' the same syntax as [select()][select.corpus()] to make it easy to move blocks
11 +
#' of columns at once.
12 +
#' 
13 +
#' @inheritParams dplyr::relocate
14 +
#' @export
15 +
#' @examples
16 +
#' data_corpus_inaugural %>%
17 +
#'   relocate(President, Party) %>%
18 +
#'   summary(n = 5)
19 +
#'
20 +
#' data_corpus_inaugural %>%
21 +
#'   relocate(FirstName, President, .before = Year) %>%
22 +
#'   summary(n = 5)
23 +
relocate.corpus <- function(.data, ...) {
24 +
  corpus_stv_byvar(.data, ..., fun = relocate)
25 +
}

@@ -4,20 +4,51 @@
Loading
4 4
#' @export
5 5
NULL
6 6
7 -
#' @name rename
8 -
#' @rdname dplyr_single
9 -
#' @importFrom dplyr rename
7 +
# Alias required for help links in downstream packages
8 +
#' @aliases select_helpers
9 +
#' @importFrom tidyselect contains
10 10
#' @export
11 -
NULL
11 +
tidyselect::contains
12 +
#' @importFrom tidyselect ends_with
13 +
#' @export
14 +
tidyselect::ends_with
15 +
#' @importFrom tidyselect everything
16 +
#' @export
17 +
tidyselect::everything
18 +
#' @importFrom tidyselect matches
19 +
#' @export
20 +
tidyselect::matches
21 +
#' @importFrom tidyselect num_range
22 +
#' @export
23 +
tidyselect::num_range
24 +
#' @importFrom tidyselect one_of
25 +
#' @export
26 +
tidyselect::one_of
27 +
#' @importFrom tidyselect starts_with
28 +
#' @export
29 +
tidyselect::starts_with
30 +
#' @importFrom tidyselect last_col
31 +
#' @export
32 +
tidyselect::last_col
33 +
#' @importFrom tidyselect any_of
34 +
#' @export
35 +
tidyselect::any_of
36 +
#' @importFrom tidyselect all_of
37 +
#' @export
38 +
tidyselect::all_of
39 +
12 40
13 -
#' Select/rename docvars by name
41 +
#' Subset docvars using their names and types
14 42
#'
15 -
#' Choose or rename document variables.  `select()` keeps only the docvars you
16 -
#' mention; `rename()` keeps all of the docvars.
43 +
#' Select (and optionally rename) document variables in a data frame, using a
44 +
#' concise mini-language that makes it easy to refer to variables based on their
45 +
#' name (e.g. `a:f` selects all columns from `a` on the left to `f` on the
46 +
#' right). You can also use predicate functions like `is.numeric` to select
47 +
#' variables based on their properties.
48 +
#' 
49 +
#' For an overview of selection features, see [dplyr::select()].
17 50
#' @param .data a \pkg{quanteda} object with document variables
18 -
#' @param ... comma-separated list of unquoted document variables.  See
19 -
#'   [select][dplyr::select()].
20 -
#' @importFrom quanteda corpus convert %>% meta
51 +
#' @inheritParams dplyr::select
21 52
#' @export
22 53
#' @examples
23 54
#' data_corpus_inaugural %>%
@@ -27,14 +58,3 @@
Loading
27 58
select.corpus <- function(.data, ...) {
28 59
  corpus_stv_byvar(.data, ..., fun = select)
29 60
}
30 -
31 -
#' @rdname select.corpus
32 -
#' @export
33 -
#' @examples
34 -
#' data_corpus_inaugural %>%
35 -
#'   rename(LastName = President) %>%
36 -
#'   select(FirstName, LastName) %>%
37 -
#'   summary(n = 5)
38 -
rename.corpus <- function(.data, ...) {
39 -
  corpus_stv_byvar(.data, ..., fun = rename)
40 -
}

@@ -0,0 +1,43 @@
Loading
1 +
#' @name rename
2 +
#' @rdname dplyr_single
3 +
#' @importFrom dplyr rename
4 +
#' @export
5 +
NULL
6 +
7 +
#' @name rename_with
8 +
#' @rdname dplyr_single
9 +
#' @importFrom dplyr rename_with
10 +
#' @export
11 +
NULL
12 +
13 +
#' Rename document variables
14 +
#'
15 +
#' `rename()` changes the names of individual document variables using `new_name
16 +
#' = old_name` syntax; `rename_with()` renames columns using a function.
17 +
#' 
18 +
#' @param .data a \pkg{quanteda} object with document variables
19 +
#' @inheritParams dplyr::rename
20 +
#' @export
21 +
#' @examples
22 +
#' data_corpus_inaugural %>%
23 +
#'   rename(LastName = President) %>%
24 +
#'   summary(n = 5)
25 +
rename.corpus <- function(.data, ...) {
26 +
  corpus_stv_byvar(.data, ..., fun = rename)
27 +
}
28 +
29 +
#' @rdname rename.corpus
30 +
#' @inheritParams dplyr::rename_with
31 +
#' @importFrom quanteda docvars<-
32 +
#' @export
33 +
#' @examples
34 +
#' data_corpus_inaugural %>%
35 +
#'   rename_with(toupper) %>%
36 +
#'   summary(n = 5)
37 +
#' data_corpus_inaugural %>%
38 +
#'   rename_with(toupper, starts_with("P")) %>%
39 +
#'   summary(n = 5)
40 +
rename_with.corpus <- function(.data, .fn, .cols = everything(), ...) {
41 +
  docvars(.data) <- rename_with(docvars(.data), .fn = .fn, .cols = .cols, ...)
42 +
  .data
43 +
}
Files Coverage
R 63.27%
Project Totals (11 files) 63.27%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading