Si vous ne me dérange pas en cours d'exécution d'une fonction pour mettre à jour votre YAML, l'exécution de ce à partir de la racine de votre colis devrait fonctionner (utilisation « Écraser = FALSE » pour le test: il va créer un _pkgdown_new. fichier YAML):.
update_yaml <- function(mypkg, overwrite = FALSE) {
require(yaml)
# _____________________________________________________________________
# Find currently missing functions in yaml file ####
curr_yaml <- yaml.load_file("_pkgdown.yaml")
curr_yaml_ref <- curr_yaml[["reference"]]
curr_funcs <- unlist(lapply(curr_yaml_ref,
FUN = function(x) (x$contents))) %>%
gsub('`', "", .)
all_pkgfuncs <- ls(paste0("package:", mypkg))
miss_funcs <- setdiff(pkg_funcs, curr_funcs)
if (length(miss_funcs) == 0) {
message("All functions are already in _pkgdown.yaml")
} else {
# _________________________________________________________________
# Look if an "Other" section already exists ####
titles <- unlist(lapply(curr_yaml_ref, FUN = function(x) (x$title)))
other_sect <- which(titles == "Other")
if (!length(other_sect) == 0) {
# _________________________________________________________________
# If the "Other" sect already exists, append missing functions ####
message(strwrap(paste(
"Adding ", paste0("`", miss_funcs, "` ", collapse = ""),
"to _pkgdown.yaml")))
curr_yaml_ref[[other_sect]] = list(
title = "Other",
desc = "Other Functions",
contents = c(curr_yaml_ref[[other_sect]]$contents,
paste0("`", miss_funcs, "`"))
)
} else {
# _____________________________________________________________
# Otherwise, create the "other" section and add ####
message("Creating the \"Others\" section")
message(strwrap(paste(
"Adding ", paste0("`", miss_funcs, "` ", collapse = ""),
"to _pkgdown.yaml")))
curr_yaml_ref[[length(curr_yaml_ref) + 1]] = list(
title = "Other",
desc = "Other Functions",
contents = paste0("`", miss_funcs, "`"))
}
curr_yaml[["reference"]] <- curr_yaml_ref
if (overwrite) {
write(as.yaml(curr_yaml), "_pkgdown.yaml")
} else {
write(as.yaml(curr_yaml), "_pkgdown_new.yaml")
}
}
}
> update_yaml("sprawl", overwrite = F)
Création la section "Autres"
Ajout er_crop_object
er_getbands
er_points
er_polygons
reproj_rast
setClasses``setinfo_rast
sprawl_scalebar
à _pkgdown.yaml
La fonction broute le fichier .yaml actuel et trouve les fonctions actuellement manquantes. S'il en existe, ils sont ajoutés à la section "Autres" du fichier .yaml (qui est automatiquement créé s'il n'est pas déjà présent). J'ai fait un test rapide et il semble fonctionner correctement.
HTH!
Pour un peu Tricker et cas d'utilisation moins efficace, voir [regex pour chaîne ne contenant ** ** plusieurs mots spécifiques] (https://stackoverflow.com/questions/7801581/regex-for-string- pas-contenant-multiple-specific-words) – C8H10N4O2
C'est une bonne idée, mais je ne pense pas que ce soit faisable pour beaucoup de fonctions (disons que vous aviez une centaine de fonctions dans le paquet. quelqu'un ajoute une nouvelle fonction mais oublie de mettre à jour le 'yml' – Shorpy