Categories Uncategorized

Définition des paramètres de fonction pour le débogage

[This article was first published on Jason Bryer, and kindly contributed to R-bloggers]. (Vous pouvez signaler un problème concernant le contenu de cette page ici)


Vous souhaitez partager votre contenu sur R-bloggers ? cliquez ici si vous avez un blog, ou ici si vous n’en avez pas.

J’ai tendance à écrire beaucoup de fonctions qui créent des graphiques spécifiques implémentés avec ggplot2. Même si j’essaie de choisir des paramètres graphiques (par exemple les couleurs, la taille du texte, etc.) qui sont raisonnables, je définirai généralement toutes les esthétiques pertinentes comme paramètres de ma fonction. En conséquence, mes fonctions ont tendance à avoir beaucoup de paramètres. Lorsque j’ai besoin de déboguer la fonction, j’ai besoin que tous ces paramètres soient définis dans l’environnement global, ce qui m’oblige généralement à mettre en évidence chaque affectation et à l’exécuter. Cette fonction automatise ce processus. Vous pouvez transmettre n’importe quelle fonction et elle tentera de définir les paramètres de l’environnement donné (l’environnement global par défaut). Il renverra un bloc de données avec une colonne indiquant si la variable a été définie et la valeur. Ceci est utile pour savoir quels paramètres n’ont pas de valeur par défaut et doivent être définis vous-même.

#' Set function parameters to an environment.
#'
#' This function is designed to help debug functions. It will attempt to set all
#' the default parameter values to the specified environment (global environment
#' by default). This is useful for when you want to execute code within the 
#' function definition interactively but need the parameters set in the current 
#' environment.
#'
#' **Warning:** This function will modify the global environment and therefore 
#' violates CRAN policy
#' ["Packages should not modify the global environment (user’s workspace)"]
#' (
#'
#' @param FUN the function to assign parameters to an environment.
#' @param envir the environment to assign the variables to. Defaults to the 
#'        global environment.
#' @param verbose whether to return the data frame invisibly or to print the results.
#' @return a data frame where row names correspond to the parameter name with 
#'        two columns: `set` which is logical indicating if the variable was set 
#'        and `value` with a character representation of the variable value.
set_function_params <- function(FUN, envir = globalenv(), verbose = interactive()) {
    params <- formals(FUN)
    params_set <- data.frame(row.names = names(params),
                             set = rep(FALSE, length(params)),
                             value = rep(NA_character_, length(params)))
    for(param in names(params)) {
        value <- params[[param]]
        if(!missing(value)) {
            if(is.character(value)) {
                assign(param, value, envir = envir)
                params_set[param,]$value <- value
            } else {
                assign(param, eval(value), envir = envir)
                params_set[param,]$value <- eval(value)
            }
            params_set[param,]$set <- TRUE
        }
    }
    if(verbose) {
        return(params_set)
    } else {
        invisible(params_set)
    }
}

Très récemment, j’essayais de déboguer une fonction qui crée des tracés de profil pour l’analyse de cluster (clav::profile_plot()documentation). Cette fonction comporte 23 paramètres ! Tout régler manuellement est assez fastidieux.

# List objects in the current environment
ls()
[1] "set_function_params"
# Call the function
param_set_result <- set_function_params(clav::profile_plot)

# Check to see if the parameters are actually set
ls()
 [1] "bonferroni"          "center_alpha"        "center_band"        
 [4] "center_fill"         "cluster_label_hjust" "color_palette"      
 [7] "hjust"               "label_clusters"      "label_means"        
[10] "label_outcome_means" "label_profile_means" "param_set_result"   
[13] "point_size"          "se_factor"           "set_function_params"
[16] "standardize"         "text_size"           "title"              
[19] "ylab"               

On peut examiner la trame de données qui donne un résumé des paramètres définis (ou non).

param_set_result
                      set               value
df                  FALSE                <NA>
clusters            FALSE                <NA>
df_dep              FALSE                <NA>
standardize          TRUE                TRUE
bonferroni           TRUE                TRUE
label_means          TRUE                TRUE
label_profile_means  TRUE                TRUE
label_outcome_means  TRUE                TRUE
center_band          TRUE                0.25
center_fill          TRUE             #f0f9e8
center_alpha         TRUE                 0.1
text_size            TRUE                   4
hjust                TRUE                 0.5
point_size           TRUE                   2
se_factor            TRUE                1.96
color_palette        TRUE                   2
cluster_labels      FALSE                <NA>
cluster_order       FALSE                <NA>
label_clusters       TRUE                TRUE
cluster_label_x     FALSE                <NA>
cluster_label_hjust  TRUE                   5
ylab                 TRUE Mean Standard Score
title                TRUE    Cluster Profiles


PakarPBN

A Private Blog Network (PBN) is a collection of websites that are controlled by a single individual or organization and used primarily to build backlinks to a “money site” in order to influence its ranking in search engines such as Google. The core idea behind a PBN is based on the importance of backlinks in Google’s ranking algorithm. Since Google views backlinks as signals of authority and trust, some website owners attempt to artificially create these signals through a controlled network of sites.

In a typical PBN setup, the owner acquires expired or aged domains that already have existing authority, backlinks, and history. These domains are rebuilt with new content and hosted separately, often using different IP addresses, hosting providers, themes, and ownership details to make them appear unrelated. Within the content published on these sites, links are strategically placed that point to the main website the owner wants to rank higher. By doing this, the owner attempts to pass link equity (also known as “link juice”) from the PBN sites to the target website.

The purpose of a PBN is to give the impression that the target website is naturally earning links from multiple independent sources. If done effectively, this can temporarily improve keyword rankings, increase organic visibility, and drive more traffic from search results.

Jasa Backlink

Download Anime Batch

Leave a Reply

Your email address will not be published. Required fields are marked *