-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstatus-setter.R
167 lines (157 loc) · 6.04 KB
/
status-setter.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
binder <- ContextBinder$new()
#' @title StatusSetter class
#' @description Internal class that manages authors' status.
#' @keywords internal
StatusSetter <- R6Class(
classname = "StatusSetter",
inherit = PlumeHandler,
public = list(
initialize = function(..., by) {
super$initialize(...)
check_string(by, allow("null"))
if (is.null(by)) {
private$by <- private$pick("id")
} else {
private$check_col(by)
private$by <- by
}
},
#' @description Set corresponding authors.
#' @param ... One or more unquoted expressions separated by commas.
#' Expressions matching values in the column defined by `by`/`.by`
#' determine corresponding authors. Matching of values is case-
#' insensitive.
#' @param .by Variable used to set corresponding authors. By default, uses
#' authors' id.
#' @param by `r lifecycle::badge("deprecated")`
#'
#' Please use the `.by` parameter instead.
#' @return The class instance.
set_corresponding_authors = function(..., .by = NULL, by = deprecated()) {
private$set_status("corresponding", ..., .by = .by, by = by)
}
),
private = list(
by = NULL,
set_status = function(col, ..., .by, by) {
check_dots_not_empty()
if (lifecycle::is_present(by)) {
call <- if (col == "corresponding") "corresponding_author" else col
call <- glue("set_{call}")
lifecycle::deprecate_stop(
"0.2.0",
glue("{call}(by)"),
glue("{call}(.by)")
)
}
by <- private$process_by(.by)
binder$bind(private$plume[[by]])
dots <- collect_dots(...)
private$plume <- mutate(
private$plume,
!!private$pick(col) := vec_in(.data[[by]], dots)
)
invisible(self)
},
process_by = function(by) {
if (is.null(by)) {
return(private$by)
}
check_string(by, allow("null"), arg = ".by")
private$check_col(by)
by
}
)
)
#' @title StatusSetterPlume class
#' @description Internal class extending `StatusSetter` for `Plume`.
#' @keywords internal
StatusSetterPlume <- R6Class(
classname = "StatusSetterPlume",
inherit = StatusSetter,
public = list(
#' @description Force one or more contributors' names to appear first in the
#' contribution list.
#' @param ... One or more unquoted expressions separated by commas.
#' Expressions matching values in the column defined by `by`/`.by`
#' determine main contributors. Expressions can be named after any role to
#' set different main contributors to different roles at once, in which
#' case the `.roles` parameter only applies roles that are not already set
#' to unnamed expressions. Matching of values is case-insensitive.
#' @param .roles Roles to assign main contributors to. If `.roles` is a
#' named vector, only the names will be used.
#' @param .by Variable used to specify which authors are main contributors.
#' By default, uses authors' id.
#' @return The class instance.
set_main_contributors = function(..., .roles = NULL, .by = NULL) {
private$set_ranks(..., .roles = .roles, .by = .by)
}
),
private = list(
set_ranks = function(..., .roles, .by) {
check_dots_not_empty()
check_character(.roles, allow("null", "unnamed"))
by <- private$process_by(.by)
vars <- private$pick("role", "contributor_rank", squash = FALSE)
dots <- collect_dots(...)
if (!(is.null(.roles) && is_named(dots))) {
dots <- propagate_names(dots, nms = .roles)
}
out <- unnest(private$plume, col = all_of(vars$role))
out <- add_contribution_ranks(out, dots, private$roles, by, vars)
private$plume <- nest(out, !!vars$role := squash(vars))
invisible(self)
}
)
)
#' @title StatusSetterPlumeQuarto class
#' @description Internal class extending `StatusSetter` for `PlumeQuarto`.
#' @keywords internal
StatusSetterPlumeQuarto <- R6Class(
classname = "StatusSetterPlumeQuarto",
inherit = StatusSetter,
public = list(
#' @description Set co-first authors.
#' @param ... One or more unquoted expressions separated by commas.
#' Expressions matching values in the column defined by `by`/`.by`
#' determine co-first authors. Matching of values is case-insensitive.
#' @param .by Variable used to specify which authors contributed equally to
#' the work. By default, uses authors' id.
#' @return The class instance.
set_cofirst_authors = function(..., .by = NULL) {
private$set_status("equal_contributor", ..., .by = .by)
},
#' @description `r lifecycle::badge("deprecated")`
#'
#' This method has been deprecated in favour of `set_cofirst_authors()`.
#' @param ... One or more unquoted expressions separated by commas.
#' Expressions matching values in the column defined by `by`/`.by`
#' determine equal contributors. Matching of values is case-insensitive.
#' @param .by Variable used to specify which authors are equal contributors.
#' By default, uses authors' id.
#' @param by `r lifecycle::badge("deprecated")`
#'
#' Please use the `.by` parameter instead.
#' @return The class instance.
set_equal_contributor = function(..., .by = NULL, by = deprecated()) {
lifecycle::deprecate_stop(
"0.2.0",
"set_equal_contributor()",
"set_cofirst_authors()"
)
},
#' @description Set deceased authors.
#' @param ... One or more unquoted expressions separated by commas.
#' Expressions matching values in the column defined by `by`/`.by`
#' determine deceased authors. Matching of values is case-insensitive.
#' @param .by Variable used to specify whether an author is deceased or not.
#' By default, uses authors' id.
#' @param by `r lifecycle::badge("deprecated")`
#'
#' Please use the `.by` parameter instead.
#' @return The class instance.
set_deceased = function(..., .by = NULL, by = deprecated()) {
private$set_status("deceased", ..., .by = .by, by = by)
}
)
)