Skip to content

Handle missingness #84

Description

@coatless

Consider the use of NA and NULL being passed into a named parameter:

gh("/repos/:owner/:repo/issues", owner = "r-lib", repo = "gh", state = NULL)
# Error in gsub(paste0(":", n, "\\b"), p, endpoint) : 
#  invalid 'replacement' argument

gh("/repos/:owner/:repo/issues", owner = "r-lib", repo = "gh", state = NA)
# Error in gh("/repos/:owner/:repo/issues", owner = "r-lib", repo = "gh",  : 
#  GitHub API error (422): 422 Unprocessable Entity
#  Validation Failed

This is a bit problematic for parameters that may be optional. (c.f. coatless-rpkg/ghapi3#3)

Would it be possible to add filtering inside of gh_set_endpoint() in R/gh_request.R to remove parameters that have R-specific missingness? e.g.

gh_set_endpoint <- function(x) {
  params <- x$params
  if (!grepl(":", x$endpoint) || length(params) == 0L || has_no_names(params)) {
    return(x)
  }

  # Subset out invalid params
  params <- Filter(Negate(is.null), params)
  params <- Filter(Negate(is.na), params)

  # rest of the logic ... 
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions