Tools to work with the Google DNS over HTTPS API in R https://cinc.rud.is/web/packages/gdns/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

as-data-frame.R 880B

1234567891011121314151617181920212223242526272829303132333435
  1. #' Coerce a gdns query response answer to a data frame
  2. #'
  3. #' Helper function to get to the `Answer` quickly
  4. #' @param x a `gdns_response` object
  5. #' @param ... unused
  6. #' @export
  7. as.data.frame.gdns_response <- function(x, ...) {
  8. if (length(x[["Answer"]]) == 0) {
  9. data.frame(
  10. name = NA_character_,
  11. type = NA_character_,
  12. ttl = NA_character_,
  13. data = NA_character_,
  14. stringsAsFactors = FALSE
  15. ) -> out
  16. } else {
  17. out <- x[["Answer"]]
  18. }
  19. if (length(x[["Question"]][["name"]])) {
  20. out[["query"]] <- x[["Question"]][["name"]][[1]]
  21. out[["qtype"]] <- x[["Question"]][["type"]][[1]]
  22. } else {
  23. out[["query"]] <- NA_character_
  24. out[["qtype"]] <- NA_character_
  25. }
  26. colnames(out) <- tolower(colnames(out))
  27. out <- out[,c("query", "qtype", "name", "type", "ttl", "data")]
  28. class(out) <- c("tbl_df", "tbl", "data.frame")
  29. out
  30. }