@@ -141,98 +141,73 @@ ScaleDiscretePosition <- ggproto("ScaleDiscretePosition", ScaleDiscrete,
141
141
}
142
142
)
143
143
144
+ # Can't use vctrs - vctrs is too restrictive for mapped_discrete
144
145
new_mapped_discrete <- function (x = double()) {
145
146
vec_assert(x , double())
146
- obj <- new_vctr(x , class = " ggplot2_mapped_discrete" )
147
- # vctrs does not support inheriting from numeric base class
148
- class(obj ) <- c(class(obj ), " numeric" )
149
- obj
147
+ class(x ) <- c(" mapped_discrete" , " numeric" )
148
+ x
150
149
}
151
150
mapped_discrete <- function (x = double()) {
152
151
if (is.null(x )) return (NULL )
153
152
x <- as.vector(x )
154
153
new_mapped_discrete(vec_cast(x , double()))
155
154
}
156
- is_mapped_discrete <- function (x ) inherits(x , " ggplot2_mapped_discrete " )
155
+ is_mapped_discrete <- function (x ) inherits(x , " mapped_discrete " )
157
156
# ' @export
158
- format.ggplot2_mapped_discrete <- function (x , ... ) format(vec_data(x ), ... )
159
- # ' @export
160
- vec_ptype2.ggplot2_mapped_discrete.ggplot2_mapped_discrete <- function (x , y , ... ) new_mapped_discrete()
161
- # ' @export
162
- vec_ptype2.ggplot2_mapped_discrete.double <- function (x , y , ... ) new_mapped_discrete()
163
- # ' @export
164
- vec_ptype2.double.ggplot2_mapped_discrete <- function (x , y , ... ) new_mapped_discrete()
165
- # ' @export
166
- vec_ptype2.ggplot2_mapped_discrete.integer <- function (x , y , ... ) new_mapped_discrete()
157
+ c.mapped_discrete <- function (... , recursive = FALSE ) {
158
+ mapped_discrete(unlist(lapply(list (... ), unclass )))
159
+ }
167
160
# ' @export
168
- vec_ptype2.integer.ggplot2_mapped_discrete <- function (x , y , ... ) new_mapped_discrete()
161
+ `[.mapped_discrete` <- function (x , ... , drop = TRUE ) {
162
+ mapped_discrete(NextMethod())
163
+ }
169
164
# ' @export
170
- vec_ptype2.ggplot2_mapped_discrete.character <- function (x , y , ... ) character ()
165
+ `[<-.mapped_discrete` <- function (x , ... , value ) {
166
+ if (length(value ) == 0 ) {
167
+ return (x )
168
+ }
169
+ value <- as.numeric(unclass(value ))
170
+ mapped_discrete(NextMethod())
171
+ }
171
172
# ' @export
172
- vec_ptype2.character.ggplot2_mapped_discrete <- function (x , y , ... ) character ()
173
+ as.data.frame.mapped_discrete <- function (x , ... ) {
174
+ as.data.frame.vector(x = unclass(x ), ... )
175
+ }
176
+
173
177
# ' @export
174
- vec_ptype2.ggplot2_mapped_discrete.factor <- function (x , y , ... ) new_mapped_discrete()
178
+ vec_ptype2.mapped_discrete.mapped_discrete <- function (x , y , ... ) new_mapped_discrete()
175
179
# ' @export
176
- vec_ptype2.factor.ggplot2_mapped_discrete <- function (x , y , ... ) new_mapped_discrete()
180
+ vec_ptype2.mapped_discrete.double <- function (x , y , ... ) new_mapped_discrete()
177
181
# ' @export
178
- vec_cast.ggplot2_mapped_discrete.ggplot2_mapped_discrete <- function (x , to , ... ) x
182
+ vec_ptype2.double.mapped_discrete <- function (x , y , ... ) new_mapped_discrete()
179
183
# ' @export
180
- vec_cast.ggplot2_mapped_discrete .integer <- function (x , to , ... ) mapped_discrete( x )
184
+ vec_ptype2.mapped_discrete .integer <- function (x , y , ... ) new_mapped_discrete( )
181
185
# ' @export
182
- vec_cast .integer.ggplot2_mapped_discrete <- function (x , to , ... ) as.integer(vec_data( x ) )
186
+ vec_ptype2 .integer.mapped_discrete <- function (x , y , ... ) new_mapped_discrete( )
183
187
# ' @export
184
- vec_cast.ggplot2_mapped_discrete.double <- function (x , to , ... ) new_mapped_discrete( x )
188
+ vec_ptype2.mapped_discrete.character <- function (x , y , ... ) character ( )
185
189
# ' @export
186
- vec_cast.double.ggplot2_mapped_discrete <- function (x , to , ... ) vec_data( x )
190
+ vec_ptype2.character.mapped_discrete <- function (x , y , ... ) character ( )
187
191
# ' @export
188
- vec_cast.character.ggplot2_mapped_discrete <- function (x , to , ... ) as.character(vec_data( x ) )
192
+ vec_ptype2.mapped_discrete.factor <- function (x , y , ... ) new_mapped_discrete( )
189
193
# ' @export
190
- vec_cast.ggplot2_mapped_discrete. factor <- function (x , to , ... ) mapped_discrete(unclass( x ) )
194
+ vec_ptype2. factor.mapped_discrete <- function (x , y , ... ) new_mapped_discrete( )
191
195
# ' @export
192
- vec_cast.factor.ggplot2_mapped_discrete <- function (x , to , ... ) factor (vec_data( x ), ... )
196
+ vec_cast.mapped_discrete.mapped_discrete <- function (x , to , ... ) x
193
197
# ' @export
194
- vec_cast.ggplot2_mapped_discrete.logical <- function (x , to , ... ) mapped_discrete(x )
195
- # ' Utilities for working with discrete values mapped to numeric domain
196
- # '
197
- # ' @param op The operator to apply
198
- # ' @param x,y items to apply the operator to
199
- # ' @param ... passed on
200
- # ' @export vec_arith.ggplot2_mapped_discrete
201
- # ' @method vec_arith ggplot2_mapped_discrete
202
- # '
203
- # ' @keywords internal
198
+ vec_cast.mapped_discrete.integer <- function (x , to , ... ) mapped_discrete(x )
204
199
# ' @export
205
- vec_arith.ggplot2_mapped_discrete <- function (op , x , y , ... ) {
206
- UseMethod(" vec_arith.ggplot2_mapped_discrete" , y )
207
- }
200
+ vec_cast.integer.mapped_discrete <- function (x , to , ... ) as.integer(as.vector(x ))
208
201
# ' @export
209
- # ' @method vec_arith.ggplot2_mapped_discrete default
210
- vec_arith.ggplot2_mapped_discrete.default <- function (op , x , y , ... ) {
211
- stop_incompatible_op(op , x , y )
212
- }
202
+ vec_cast.mapped_discrete.double <- function (x , to , ... ) new_mapped_discrete(x )
213
203
# ' @export
214
- # ' @method vec_arith.ggplot2_mapped_discrete ggplot2_mapped_discrete
215
- vec_arith.ggplot2_mapped_discrete.ggplot2_mapped_discrete <- function (op , x , y , ... ) {
216
- mapped_discrete(vec_arith_base(op , x , y ))
217
- }
204
+ vec_cast.double.mapped_discrete <- function (x , to , ... ) as.vector(x )
218
205
# ' @export
219
- # ' @method vec_arith.ggplot2_mapped_discrete numeric
220
- vec_arith.ggplot2_mapped_discrete.numeric <- function (op , x , y , ... ) {
221
- mapped_discrete(vec_arith_base(op , x , y ))
222
- }
206
+ vec_cast.character.mapped_discrete <- function (x , to , ... ) as.character(as.vector(x ))
223
207
# ' @export
224
- # ' @method vec_arith.numeric ggplot2_mapped_discrete
225
- vec_arith.numeric.ggplot2_mapped_discrete <- function (op , x , y , ... ) {
226
- mapped_discrete(vec_arith_base(op , x , y ))
227
- }
208
+ vec_cast.mapped_discrete.factor <- function (x , to , ... ) mapped_discrete(as.vector(unclass(x )))
228
209
# ' @export
229
- # ' @method vec_arith.ggplot2_mapped_discrete MISSING
230
- vec_arith.ggplot2_mapped_discrete.MISSING <- function (op , x , y , ... ) {
231
- op_fn <- getExportedValue(" base" , op )
232
- mapped_discrete(op_fn(vec_data(x )))
233
- }
210
+ vec_cast.factor.mapped_discrete <- function (x , to , ... ) factor (as.vector(x ), ... )
234
211
# ' @export
235
- vec_math.ggplot2_mapped_discrete <- function (.fn , .x , ... ) {
236
- res <- vec_math_base(.fn , .x , ... )
237
- if (is.numeric(res )) mapped_discrete(res ) else res
238
- }
212
+ vec_cast.mapped_discrete.logical <- function (x , to , ... ) mapped_discrete(x )
213
+
0 commit comments