Skip to content

Instantly share code, notes, and snippets.

@romainfrancois
Created December 14, 2017 13:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romainfrancois/6576c7a57fc707b4ca5d45f05d76c8a7 to your computer and use it in GitHub Desktop.
Save romainfrancois/6576c7a57fc707b4ca5d45f05d76c8a7 to your computer and use it in GitHub Desktop.
history if is.na
library(tidyverse)
library(glue)
# i have my reasons, please dont burn my computer
setwd("~/git/r-source")
extract_isna <- function(.){
cat( "\r", . )
invisible( system(paste0('git checkout -q -f ', .)) )
if( !file.exists("src/main/coerce.c")) return("")
lines <- read_lines("src/main/coerce.c")
start <- grep( "SEXP.*do_isna[(]", lines)
if( !length(start)) return("")
end <- grep( "^}", lines)
end <- first( end[ end > start ] )
paste( lines[ seq(start, end) ], collapse = "\n" )
}
realsxp_case <- function(.){
txt <- str_split(., "\n")[[1]]
start <- grep( "case REALSXP", txt )[1]
end <- grep( "case", txt)
end <- end[ end > start ][1]
paste( txt[ seq(start+1, end-1) ], collapse = "\n" )
}
commits <- system("git rev-list --pretty=oneline --all -- src/main/coerce.c", intern = TRUE) %>%
tibble( x = .) %>%
separate(x, into = c("id", "msg"), sep= " ", extra = "merge")
data <- commits %>%
mutate( isna = map_chr(id, extract_isna)) %>%
filter( isna != "") %>%
mutate( case_realsxp = map_chr( isna, realsxp_case) )
data %>%
slice(n():1) %>%
distinct( case_realsxp ) %>%
pull()
@romainfrancois
Copy link
Author

> data %>% slice(n():1) %>% distinct( case_realsxp ) %>% pull() 
[1] "\t\tfor (i = 0; i < length(x); i++)\n\t\t\tLOGICAL(ans)[i] = !FINITE(REAL(x)[i]);\n\t\tbreak;"                                                                                                              
[2] "\t\tfor (i = 0; i < length(x); i++)\n\t\t\tLOGICAL(ans)[i] = NAN(REAL(x)[i]);\n\t\tbreak;"                                                                                                                  
[3] "\t\tfor (i = 0; i < length(x); i++)\n\t\t\tLOGICAL(ans)[i] = ISNAN(REAL(x)[i]);\n\t\tbreak;"                                                                                                                
[4] "\tfor (i = 0; i < length(x); i++)\n\t    LOGICAL(ans)[i] = ISNAN(REAL(x)[i]);\n\tbreak;"                                                                                                                    
[5] "\tfor (i = 0; i < n; i++)\n\t    LOGICAL(ans)[i] = ISNAN(REAL(x)[i]);\n\tbreak;"                                                                                                                            
[6] "\tfor (i = 0; i < n; i++)\n\t    LOGICAL(ans)[i] = ISNAN(REAL(x)[i]);\n\t    break;"                                                                                                                        
[7] "\tans = REAL_IS_NA(x);\n\tbreak;\n    }\n    if(ans != NULL) {\n\tPROTECT(ans); nprot++;\n    } else {\n\tPROTECT(ans = allocVector(LGLSXP, n));nprot++;\n\tswitch (TYPEOF(x)) {"                           
[8] "\tfor (i = 0; i < n; i++)\n\t    pa[i] = ISNAN(REAL_ELT(x, i));\n\tbreak;"                                                                                                                                  
[9] "\tans = REAL_IS_NA(x);\n\tbreak;\n    }\n    if(ans != NULL) {\n\tPROTECT(ans); nprot++;\n    } else {\n\tPROTECT(ans = allocVector(LGLSXP, n));nprot++;\n\tint *pa = LOGICAL(ans);\n\tswitch (TYPEOF(x)) {"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment