Created
June 26, 2024 22:47
-
-
Save coolbutuseless/b2419880c6cf4199505de174c9b9d9c2 to your computer and use it in GitHub Desktop.
Deparse summarises non-altrep integer vectors to a range
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# remotes::install_github("multimeric/altrepr") | |
library(altrepr) | |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
# Create a long vector of consecutive INTEGER values | |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
int_vec_str <- sprintf("c(%s)", paste(5:(2^18), 'L', sep = '', collapse = ", ")) | |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
# Simply creating the integer vector doesn't make it an altrep | |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
int_vec <- eval(parse(text = int_vec_str)) | |
int_vec | |
is.integer(int_vec) | |
altrepr::is_altrep(int_vec) | |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
# 'deparse1()' then detects this is a range and summarises it as "first:last" | |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
deparse(int_vec) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment