-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clean obsolete files in R, tests or vignettes #24
Comments
Hello @statnmap, I don't know if this helps, but here is the code I produced to identify the "obsolete" functions. It compares the functions present in the "flat" files (using the names of the chunks I excluded the functions from the package that were not built with flat files (notably functions related to the shiny app, and utils functions).
|
Hey, Quick thoughts on this code :
```{r function-https, file.name = "https"}
#' HTTP req
#'
#' @importFrom cli cli_alert_success cli_alert_danger
#' @importFrom httr GET POST add_headers status_code content
#'
#' @return Un objet response de {httr}, lisible avec httr::content()
#' @noRd
#' @rdname HTTP
health_check <- function(
url
) {
# [...]
}
```
```{r function-https, file.name = "https"}
#' HTTP req
#'
#' @importFrom cli cli_alert_success cli_alert_danger
#' @importFrom httr GET POST add_headers status_code content
#'
#' @return Un objet response de {httr}, lisible avec httr::content()
#' @noRd
#' @rdname HTTP
health_check <- function(
url
) {
# [...]
}
#' @noRd
#' @rdname HTTP
delete_ <- function(url, expected_status_code = 200) {
# [...]
}
``` |
Tags: feat, doc, test Ongoing feature creation. - Retrieve file path created during inflate - Start to store in a yaml file Issue #24
Tags: feat, doc, test Why? - To create a config file for already existing {fusen}, we need not to detect files that should not be deleted What? WIP: - List all files and try to guess origin - Show the user all files not registered and allow them to manually clean issue #24
Tags: feat, test, doc Why? - Need to migrate package to the new config file management What? - Allow `df_to_config()` to run on the output of `check_not_registered_files()` Issue #24
tags: feat, test, doc Why? - Users would want to use the new config file in the new fusen version, without having to write it themselves if coming from older version or classical package What? - Add `register_all_to_config()` Issue #24
tags: doc Why? - Function is done, it can be inflated in the package What? - Just inflate issue #24
Tags: feat, doc, test Ongoing feature creation. - Retrieve file path created during inflate - Start to store in a yaml file Issue #24
Tags: feat, doc, test Why? - To create a config file for already existing {fusen}, we need not to detect files that should not be deleted What? WIP: - List all files and try to guess origin - Show the user all files not registered and allow them to manually clean issue #24
Tags: feat, test, doc Why? - Need to migrate package to the new config file management What? - Allow `df_to_config()` to run on the output of `check_not_registered_files()` Issue #24
tags: feat, test, doc Why? - Users would want to use the new config file in the new fusen version, without having to write it themselves if coming from older version or classical package What? - Add `register_all_to_config()` Issue #24
tags: doc Why? - Function is done, it can be inflated in the package What? - Just inflate issue #24
tags: fix, doc, test Why? - All examples need to run properly What? - UPdate flat file for clean_fusen_files - Update documentation to explain how it will work - fix tests and examples Issue #24
Tags: feat, doc, test Ongoing feature creation. - Retrieve file path created during inflate - Start to store in a yaml file Issue #24
Tags: feat, doc, test Why? - To create a config file for already existing {fusen}, we need not to detect files that should not be deleted What? WIP: - List all files and try to guess origin - Show the user all files not registered and allow them to manually clean issue #24
Tags: feat, test, doc Why? - Need to migrate package to the new config file management What? - Allow `df_to_config()` to run on the output of `check_not_registered_files()` Issue #24
tags: feat, test, doc Why? - Users would want to use the new config file in the new fusen version, without having to write it themselves if coming from older version or classical package What? - Add `register_all_to_config()` Issue #24
tags: doc Why? - Function is done, it can be inflated in the package What? - Just inflate issue #24
tags: fix, doc, test Why? - All examples need to run properly What? - UPdate flat file for clean_fusen_files - Update documentation to explain how it will work - fix tests and examples Issue #24
tags: fix, test, doc Why? - `data.frame()` and `read.csv()` read string as factors in old R versions, preventing them to be used as file path What? - Added stringAsFactors = FALSE everywhere needed issue #24
tags: feat, doc, test Why? - More info needs to be stored in the config_fusen.yaml file. What? - Allow test to be ok with extra information - TODO: define 'df_to_config()' to only bother about path, R, tests, vignette issue #24
A function to detect if there are duplicate names in "R/". parse_fun_vec <- function(code) {
# code <- unlist(rmd_node_code(x[["ast"]]))
regex_isfunction <- paste("function(\\s*)\\(", "R6Class(\\s*)\\(",
sep = "|")
regex_extract_fun_name <- paste("[\\w[.]]*(?=(\\s*)(<-|=)(\\s*)function)",
"[\\w[.]]*(?=(\\s*)(<-|=)(\\s*)R6Class)", "[\\w[.]]*(?=(\\s*)(<-|=)(\\s*)R6::R6Class)",
sep = "|")
fun_name <- stringi::stri_extract_first_regex(code[grep(regex_isfunction,
code)], regex_extract_fun_name) %>% gsub(" ", "", .)
code <- gsub(pattern = "#'\\s*@", "#' @", code)
first_function_start <- grep(regex_isfunction, code)[1]
all_hastags <- grep("^#'", code)
if (length(all_hastags) != 0) {
last_hastags_above_first_fun <- max(all_hastags[all_hastags <
first_function_start])
}
else {
last_hastags_above_first_fun <- NA
}
if (!any(grepl("@export|@noRd", code))) {
if (!is.na(last_hastags_above_first_fun)) {
code <- c(code[1:last_hastags_above_first_fun], "#' @noRd",
code[(last_hastags_above_first_fun + 1):length(code)])
}
else if (all(grepl("^\\s*$", code))) {
code <- character(0)
}
else if (!is.na(first_function_start)) {
code <- c("#' @noRd", code)
}
}
all_arobase <- grep("^#'\\s*@|function(\\s*)\\(", code)
example_pos_start <- grep("^#'\\s*@example", code)[1]
example_pos_end <- all_arobase[all_arobase > example_pos_start][1] -
1
example_pos_end <- ifelse(is.na(example_pos_end), grep("function(\\s*)\\(",
code) - 1, example_pos_end)
tag_filename <- gsub("^#'\\s*@filename\\s*", "", code[grep("^#'\\s*@filename",
code)])
tag_rdname <- gsub("^#'\\s*@rdname\\s*", "", code[grep("^#'\\s*@rdname",
code)])
rox_filename <- c(tag_filename, tag_rdname)[1]
code[grep("^#'\\s*@filename", code)] <- "#'"
tibble::tibble(fun_name = fun_name[1], code = list(code),
example_pos_start = example_pos_start, example_pos_end = example_pos_end,
rox_filename = rox_filename)
}
get_duplicate_functions <- function(path = "R") {
all_r <- list.files(path, full.names = TRUE)
all_funs <- lapply(all_r, function( one_r) {
# one_r <- all_r[1]
r_lines <- readLines(one_r)
parse_fun_vec(r_lines)
})
res <- do.call("rbind", all_funs)
res_clean <- res[!is.na(res[["fun_name"]]),]
res_dups <- res_clean[["fun_name"]][duplicated(res_clean[["fun_name"]])]
if (length(res_dups) != 0) {
message('There are duplicated function names:', paste(res_dups, collapse = ", "))
}
list(
all_funs = res_clean,
duplicated = res_dups
)
}
} |
tags: feat, doc Why? - Next {fusen} version will come with big changes, the version number will be an index to trigger (or not) new functions What? - Add {fusen} version number in the DESCRIPTION file issue #24
tags: fix, doc Why? Syntax with `Config/` does not fail on CRAN issue #24
Keep both version when conflicts Issue #24 Merge branch '24-rebase2-clean-yourself' into 24-rebase3-clean-yourself # Conflicts: # R/inflate.R # tests/testthat/test-inflate-part2.R
tags: fix, feat, test, doc Why? - We may want to register some files after some manual modifications issue #24
tags: chore, feat, test, doc Why? - It is time to integrate the new feature to the mainstream. - The sets a major step towards the cleaning functions to be coming soon (#24) What? - Bump version but keep it as a .9000 to avoid updating vignettes in the pkgdown file - Change path in "do not edit by hand" for a relative path that do not start with "/" issue #24
tags: feat, test - Include this feature in the next release so that users will benefit from the cleaning tools in the next release - Encourage to use `register_all_to_cnofig()` for the transition to this new version of {fusen} - Requires doc for inflate_all() - requires unit tests to check that this functionnality works correctly issue #24
tags: feat, doc, test - check_unregistered_file during inflate_all() - This can be avoided with `clean=FALSE` - Update doc links between functions issue #24
tags: fix, test - R <= 3.6 requires change default stringasfactors parameter issue #24
Delete files that are no longer needed when detected by inflating issue #24
Since 'fusen' registers files created during inflate in the config_fusen file, it knows what was the name of the created files in the previous inflate. Hence, we can ask to 'clean' these files directly. |
Validation
During
inflate_all()
:clean = TRUE
to delete without question.function
chunk, a new R, tests files will be created. I would like the R and tests files of the older name to be deleted when I inflate my flat file, whether I am asked or directly withclean = TRUE
Tech
Development will mainly take place in : "dev/flat_clean_fusen_files.Rmd"
Level of the package
check_not_registered_files()
to ask if: you want to delete all or you want to register all (hence, runregister_all_to_config()
) or register only a part of it ?delete_all_not_registered()
for the delete part"config_not_registered.csv"
and then we need to tell them to rundelete_all_not_registered()
after that.Level of the inflate of one flat file
df_to_config(flat_file_path = relative_flat_file)
when used duringinflate()
so that theclean = TRUE
parameter also asks to clean R, tests or vignettesThe text was updated successfully, but these errors were encountered: