3838# ' [quantile.integer64()], [median.integer64()], and [summary.integer64()]
3939# '
4040# ' @examples
41- # ' x <- as.integer64(sample(c(rep(NA, 9), 1:9), 32, TRUE))
42- # ' y <- x
41+ # ' x = as.integer64(sample(c(rep(NA, 9), 1:9), 32, TRUE))
42+ # ' y = x
4343# ' bit::still.identical(x, y)
44- # ' y[1] <- NA
44+ # ' y[1] = NA
4545# ' bit::still.identical(x, y)
46- # ' mycache <- newcache(x)
46+ # ' mycache = newcache(x)
4747# ' ls(mycache)
4848# ' mycache
4949# ' rm(mycache)
5050# ' jamcache(x)
5151# ' cache(x)
52- # ' x[1] <- NA
52+ # ' x[1] = NA
5353# ' cache(x)
5454# ' getcache(x, "abc")
5555# ' setcache(x, "abc", 1)
6262
6363# ' @describeIn cache creates a new cache referencing `x`
6464# ' @export
65- newcache <- function (x ) {
66- env <- new.env()
67- vmode <- typeof(x )
65+ newcache = function (x ) {
66+ env = new.env()
67+ vmode = typeof(x )
6868 if (vmode == " double" && is.integer64(x ))
69- vmode <- " integer64"
69+ vmode = " integer64"
7070 setattr(env , " class" , c(paste(" cache" , vmode , sep = " _" ), " cache" , " environment" ))
7171 assign(" x" , x , envir = env )
7272 env
7373}
7474
7575# ' @describeIn cache forces `x` to have a cache
7676# ' @export
77- jamcache <- function (x ) {
78- cache <- attr(x , " cache" )
77+ jamcache = function (x ) {
78+ cache = attr(x , " cache" )
7979 if (is.null(cache )) {
80- cache <- newcache(x )
80+ cache = newcache(x )
8181 setattr(x , " cache" , cache )
8282 } else if (! still.identical(x , get(" x" , envir = cache , inherits = FALSE ))) {
83- cache <- newcache(x )
83+ cache = newcache(x )
8484 setattr(x , " cache" , cache )
8585 warning(" replaced outdated cache with empty cache" )
8686 }
@@ -90,8 +90,8 @@ jamcache <- function(x) {
9090# ' @describeIn cache returns the cache attached to `x` if it is not
9191# ' found to be outdated
9292# ' @export
93- cache <- function (x ) {
94- cache <- attr(x , " cache" )
93+ cache = function (x ) {
94+ cache = attr(x , " cache" )
9595 if (is.null(cache ) || still.identical(x , get(" x" , envir = cache , inherits = FALSE ))) {
9696 cache
9797 } else {
@@ -105,16 +105,16 @@ cache <- function(x) {
105105# ' @param which A character naming the object to be retrieved from the cache or to be stored in the cache
106106# ' @param value An object to be stored in the cache
107107# ' @export
108- setcache <- function (x , which , value ) {
109- env <- jamcache(x )
108+ setcache = function (x , which , value ) {
109+ env = jamcache(x )
110110 assign(which , value , envir = env )
111111 env
112112}
113113
114114# ' @describeIn cache gets cache value 'which' from `x`
115115# ' @export
116- getcache <- function (x , which ) {
117- cache <- attr(x , " cache" )
116+ getcache = function (x , which ) {
117+ cache = attr(x , " cache" )
118118 if (is.null(cache ))
119119 return (NULL )
120120 if (still.identical(x , get(" x" , envir = cache , inherits = FALSE ))) {
@@ -131,7 +131,7 @@ getcache <- function(x, which) {
131131
132132# ' @describeIn cache removes the cache from `x`
133133# ' @export
134- remcache <- function (x ) {
134+ remcache = function (x ) {
135135 setattr(x , " cache" , NULL )
136136 invisible ()
137137}
@@ -140,8 +140,8 @@ remcache <- function(x) {
140140# ' @param all.names,pattern passed to [ls()] when listing the cache content
141141# ' @param ... ignored
142142# ' @export
143- print.cache <- function (x , all.names = FALSE , pattern , ... ) {
144- l <- ls(x , all.names , pattern = pattern )
143+ print.cache = function (x , all.names = FALSE , pattern , ... ) {
144+ l = ls(x , all.names , pattern = pattern )
145145 cat(class(x )[1L ], " : " , paste(l , collapse = " - " ), " \n " , sep = " " )
146146 invisible (l )
147147}
@@ -175,18 +175,18 @@ print.cache<- function(x, all.names=FALSE, pattern, ...) {
175175# ' from small caches
176176# '
177177# ' @examples
178- # ' x <- as.integer64(sample(c(rep(NA, 9), 1:9), 32, TRUE))
178+ # ' x = as.integer64(sample(c(rep(NA, 9), 1:9), 32, TRUE))
179179# ' sortordercache(x)
180180# '
181181# ' @keywords environment
182182# ' @export
183- hashcache <- function (x , nunique = NULL , ... ) {
184- env <- jamcache(x )
183+ hashcache = function (x , nunique = NULL , ... ) {
184+ env = jamcache(x )
185185 if (is.null(nunique ))
186- nunique <- env $ nunique
187- env <- hashmap(x , nunique = nunique , cache = env , ... )
186+ nunique = env $ nunique
187+ env = hashmap(x , nunique = nunique , cache = env , ... )
188188 if (is.null(nunique ) && env $ nunique < sqrt(length(x )))
189- env <- hashmap(x , nunique = env $ nunique , cache = env , ... )
189+ env = hashmap(x , nunique = env $ nunique , cache = env , ... )
190190 na.count(x ) # since x has cache, na.count() will update the cache, unless its already there
191191 # different from sortcache, ordercache and sortordercache we do not set nties: hastab is too expensive
192192 invisible (env )
@@ -197,17 +197,17 @@ hashcache <-function(x, nunique=NULL, ...) {
197197# ' `NA`s. If we know we don't have `NA`s, this may speed-up. _Note_ that you
198198# ' risk a crash if there are unexpected `NA`s with `has.na=FALSE`.
199199# ' @export
200- sortcache <- function (x , has.na = NULL ) {
200+ sortcache = function (x , has.na = NULL ) {
201201 if (is.null(has.na )) {
202- na.count <- getcache(x , " na.count" )
202+ na.count = getcache(x , " na.count" )
203203 if (is.null(na.count ))
204- has.na <- TRUE
204+ has.na = TRUE
205205 else
206- has.na <- na.count > 0L
206+ has.na = na.count > 0L
207207 }
208- s <- clone(x )
209- na.count <- ramsort(s , has.na = has.na , na.last = FALSE , decreasing = FALSE , stable = FALSE , optimize = " time" )
210- nut <- .Call(C_r_ram_integer64_sortnut , x = s )
208+ s = clone(x )
209+ na.count = ramsort(s , has.na = has.na , na.last = FALSE , decreasing = FALSE , stable = FALSE , optimize = " time" )
210+ nut = .Call(C_r_ram_integer64_sortnut , x = s )
211211 setcache(x , " sort" , s )
212212 setcache(x , " na.count" , na.count )
213213 setcache(x , " nunique" , nut [[1L ]])
@@ -219,26 +219,26 @@ sortcache <- function(x, has.na = NULL) {
219219# ' @param stable boolean scalar defining whether stable sorting is needed. Allowing
220220# ' non-stable may speed-up.
221221# ' @export
222- sortordercache <- function (x , has.na = NULL , stable = NULL ) {
222+ sortordercache = function (x , has.na = NULL , stable = NULL ) {
223223 if (is.null(has.na )) {
224- na.count <- getcache(x , " na.count" )
224+ na.count = getcache(x , " na.count" )
225225 if (is.null(na.count ))
226- has.na <- TRUE
226+ has.na = TRUE
227227 else
228- has.na <- na.count > 0L
228+ has.na = na.count > 0L
229229 }
230230 if (is.null(stable )) {
231- nunique <- getcache(x , " nunique" )
231+ nunique = getcache(x , " nunique" )
232232 if (is.null(nunique ))
233- stable <- TRUE
233+ stable = TRUE
234234 else
235- stable <- nunique < length(x )
235+ stable = nunique < length(x )
236236 }
237- s <- clone(x )
238- o <- seq_along(x )
239- na.count <-
237+ s = clone(x )
238+ o = seq_along(x )
239+ na.count =
240240 ramsortorder(s , o , has.na = has.na , na.last = FALSE , decreasing = FALSE , stable = stable , optimize = " time" )
241- nut <- .Call(C_r_ram_integer64_sortnut , x = s )
241+ nut = .Call(C_r_ram_integer64_sortnut , x = s )
242242 setcache(x , " sort" , s )
243243 setcache(x , " order" , o )
244244 setcache(x , " na.count" , na.count )
@@ -251,25 +251,25 @@ sortordercache <- function(x, has.na = NULL, stable = NULL) {
251251# ' @param optimize by default ramsort optimizes for 'time' which requires more RAM,
252252# ' set to 'memory' to minimize RAM requirements and sacrifice speed.
253253# ' @export
254- ordercache <- function (x , has.na = NULL , stable = NULL , optimize = " time" ) {
254+ ordercache = function (x , has.na = NULL , stable = NULL , optimize = " time" ) {
255255 if (is.null(has.na )) {
256- na.count <- getcache(x , " na.count" )
256+ na.count = getcache(x , " na.count" )
257257 if (is.null(na.count ))
258- has.na <- TRUE
258+ has.na = TRUE
259259 else
260- has.na <- na.count > 0L
260+ has.na = na.count > 0L
261261 }
262262 if (is.null(stable )) {
263- nunique <- getcache(x , " nunique" )
263+ nunique = getcache(x , " nunique" )
264264 if (is.null(nunique ))
265- stable <- TRUE
265+ stable = TRUE
266266 else
267- stable <- nunique < length(x )
267+ stable = nunique < length(x )
268268 }
269- o <- seq_along(x )
270- na.count <-
269+ o = seq_along(x )
270+ na.count =
271271 ramorder(x , o , has.na = has.na , na.last = FALSE , decreasing = FALSE , stable = stable , optimize = optimize )
272- nut <- .Call(C_r_ram_integer64_ordernut , table = x , order = o )
272+ nut = .Call(C_r_ram_integer64_ordernut , table = x , order = o )
273273 setcache(x , " order" , o )
274274 setcache(x , " na.count" , na.count )
275275 setcache(x , " nunique" , nut [[1L ]])
@@ -302,7 +302,7 @@ ordercache <- function(x, has.na = NULL, stable = NULL, optimize = "time") {
302302# ' [cache()] for caching functions and [sortordercache()] for functions creating big caches
303303# '
304304# ' @examples
305- # ' x <- as.integer64(sample(c(rep(NA, 9), 1:9), 32, TRUE))
305+ # ' x = as.integer64(sample(c(rep(NA, 9), 1:9), 32, TRUE))
306306# ' length(x)
307307# ' bit::na.count(x)
308308# ' bit::nvalid(x)
@@ -317,56 +317,56 @@ NULL
317317
318318# ' @describeIn is.sorted.integer64 returns the number of `NA`s
319319# ' @export
320- na.count.integer64 <- function (x , ... ) {
321- env <- cache(x )
320+ na.count.integer64 = function (x , ... ) {
321+ env = cache(x )
322322 if (is.null(env ))
323323 return (.Call(C_r_ram_integer64_nacount , x = x ))
324324 if (exists(" na.count" , envir = env , inherits = FALSE ))
325325 return (get(" na.count" , envir = env , inherits = FALSE ))
326- ret <- .Call(C_r_ram_integer64_nacount , x = x )
326+ ret = .Call(C_r_ram_integer64_nacount , x = x )
327327 assign(" na.count" , ret , envir = env )
328328 ret
329329}
330330
331331# ' @describeIn is.sorted.integer64 returns the number of valid data points,
332332# ' usually [length()] minus `na.count`.
333333# ' @export
334- nvalid.integer64 <- function (x , ... ) {
334+ nvalid.integer64 = function (x , ... ) {
335335 length(x ) - na.count(x )
336336}
337337
338338# ' @describeIn is.sorted.integer64 checks for sortedness of `x` (NAs sorted first)
339339# ' @export
340- is.sorted.integer64 <- function (x , ... ) {
341- env <- cache(x )
340+ is.sorted.integer64 = function (x , ... ) {
341+ env = cache(x )
342342 if (is.null(env ))
343343 return (.Call(C_r_ram_integer64_issorted_asc , x = x ))
344344 if (exists(" is.sorted" , envir = env , inherits = FALSE ))
345345 return (get(" is.sorted" , envir = env , inherits = FALSE ))
346- ret <- .Call(C_r_ram_integer64_issorted_asc , x = x )
346+ ret = .Call(C_r_ram_integer64_issorted_asc , x = x )
347347 assign(" is.sorted" , ret , envir = env )
348348 ret
349349}
350350
351351# ' @describeIn is.sorted.integer64 returns the number of unique values
352352# ' @export
353- nunique.integer64 <- function (x , ... ) {
354- env <- cache(x )
353+ nunique.integer64 = function (x , ... ) {
354+ env = cache(x )
355355 if (is.null(env ))
356- has.cache <- FALSE
356+ has.cache = FALSE
357357 else if (exists(" nunique" , envir = env , inherits = FALSE ))
358358 return (get(" nunique" , envir = env , inherits = FALSE ))
359359 else # nolint: unreachable_code_linter. TODO(r-lib/lintr#2710): Re-enable.
360- has.cache <- TRUE
360+ has.cache = TRUE
361361 if (is.sorted(x )) {
362- ret <- .Call(C_r_ram_integer64_sortnut , x = x )
362+ ret = .Call(C_r_ram_integer64_sortnut , x = x )
363363 if (has.cache ) {
364364 assign(" nunique" , ret [1L ], envir = env )
365365 assign(" nties" , ret [2L ], envir = env )
366366 }
367367 ret [1L ]
368368 } else {
369- h <- hashmap(x )
369+ h = hashmap(x )
370370 if (has.cache )
371371 assign(" nunique" , h $ nunique , envir = env )
372372 h $ nunique
@@ -375,17 +375,17 @@ nunique.integer64 <- function(x, ...) {
375375
376376# ' @describeIn is.sorted.integer64 returns the number of tied values.
377377# ' @export
378- nties.integer64 <- function (x , ... ) {
379- cv <- getcache(x , " nties" )
378+ nties.integer64 = function (x , ... ) {
379+ cv = getcache(x , " nties" )
380380 if (is.null(cv )) {
381381 if (is.sorted(x )) {
382- cv <- .Call(C_r_ram_integer64_sortnut , x = x )[2L ]
382+ cv = .Call(C_r_ram_integer64_sortnut , x = x )[2L ]
383383 } else {
384- s <- clone(x )
384+ s = clone(x )
385385 # nolint next: object_usage_linter. Keep the output of in-place ramsort for debugging.
386- na.count <-
386+ na.count =
387387 ramsort(s , has.na = TRUE , na.last = FALSE , decreasing = FALSE , stable = FALSE , optimize = " time" )
388- cv <- .Call(C_r_ram_integer64_sortnut , x = s )[[2L ]]
388+ cv = .Call(C_r_ram_integer64_sortnut , x = s )[[2L ]]
389389 }
390390 }
391391 cv
0 commit comments