Skip to content

Avoiding magic strings #1

@MarkEdmondson1234

Description

@MarkEdmondson1234

One re-factor I'd like to see is removing the long strings in the code and replacing them with template files

For example instead of:

     scopes_text <- glue::glue("\n\t",
                               "#' Get a list of scopes needed for an API function",
                               "\n\t",
                               "#' This function returns the list of needed scopes for a given API function.",
                               "\n\t",
                               "#'",
                               "' @seealso \\href{{https://developers.google.com/identity/protocols/oauth2/scopes}}",
                               "\n\t",
                               "#' @param function_name The name of the API function to return scopes for.",
                               "\n\t",
                               "#' @param return_all Whether to return all scopes for the API. Defaults to FALSE.",
                               "\n\t",
                               "#' @export",
                               "\n\t",
                               "get_function_scopes <- function(function_name = NULL, return_all = F){{",
                               "\n\n\t\t",
                               "# Return all scopes",
                               "\n\t\t",
                               "scopes <- c(",
                               .trim = F)

have a template file in inst/templates/ and edit that file instead, with the code adding the parameters

scopes_text <- load_template("inst/templates/scopes.txt", params = c(blah, bleugh, boo))

Its a lot easier to manage.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions