-
-
Save jimbrig/92f5623bf8a7c9fe35847286eebe0ed0 to your computer and use it in GitHub Desktop.
Read R’s C headers to identify where R functions are coming from
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
| library(dplyr) | |
| api <- as_tibble(tools:::funAPI()) | |
| # list all header files from include dir | |
| header_files <- list.files( | |
| R.home("include"), | |
| full.names = TRUE, | |
| recursive = TRUE, | |
| pattern = "*.h" | |
| ) | |
| read_header <- function(.h) { | |
| # find include dir | |
| include_dir <- R.home("include") | |
| # generate the clang ar #thanksChatGPT | |
| system_cmd <- sprintf( | |
| "clang -Xclang -ast-dump=json -fsyntax-only -x c -I%s %s", | |
| include_dir, | |
| .h | |
| ) | |
| # parse and read | |
| json <- paste(system(system_cmd, intern = TRUE), collapse = "") | |
| in_header <- yyjsonr::read_json_str(json)[[c("inner", "name")]] | |
| header_fns <- tibble( | |
| name = in_header, | |
| header_path = gsub(paste0(include_dir, "/"), "", .h) | |
| ) | |
| header_fns | |
| } | |
| all_api_fns <- lapply(header_files, read_header) |> | |
| bind_rows() | |
| res <- inner_join(api, all_api_fns, by = "name") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment