R/test.R

Defines functions r_cshift

#' @export
r_cshift <- function(x, n) {
  lx <- length(x)
  # stopifnot(is_scalar_integerish(n), abs(n) < lx)
  # storage.mode(n) <- "integer"
  n <- as.integer(n)

  if (n < 0L)
    n <- lx+n

  x[c( (n+1L):lx, 1L:n)]
}

if(FALSE) {

  x <- as.numeric(1:1000)
  n <- 20
  r <- bench::mark(cshift(x, n), r_cshift(x, n), min_time = 2)
  plot(r)
  library(dplyr)
  r %>%
    mutate(per_diff = as.numeric(median / median[1])) %>%
    select(per_diff, everything())

  str(cshift(as.numeric(1:10), 3))
  str(cshift(as.integer(1:10), 3))
  str(cshift(as.complex(1:10), 3))
  # str(cshift(as.character(1:10), 3))
  # str(cshift(as.list(1:10), 3))

}
t-kalinowski/rfort documentation built on April 9, 2020, 6:17 a.m.