Skip to content

Commit

Permalink
Merge pull request #62 from schochastics/get_basename
Browse files Browse the repository at this point in the history
added basename (fix #56)
  • Loading branch information
schochastics authored Oct 16, 2023
2 parents b71974e + 1db3c18 commit 5987cf7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
13 changes: 13 additions & 0 deletions R/get.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#' ada_get_search(url)
#' ada_get_protocol(url)
#' ada_get_domain(url)
#' ada_get_basename(url)
#' ## these functions are vectorized
#' urls <- c("http://www.google.com", "http://www.google.com:80", "noturl")
#' ada_get_port(urls)
Expand Down Expand Up @@ -115,3 +116,15 @@ ada_get_domain <- function(url, decode = TRUE) {
}
return(res)
}

#' @rdname ada_get_href
#' @export
ada_get_basename <- function(x) {
protocol <- ada_get_protocol(x)
not_na <- !is.na(protocol)
tmp <- protocol[not_na]
host <- ada_get_hostname(x[not_na])
basename <- rep(NA_character_, length(x))
basename[not_na] <- paste0(tmp, "//", host)
basename
}
4 changes: 3 additions & 1 deletion tests/testthat/test-get.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ test_that("all get functions work", {
expect_equal(ada_get_search(url), "?q=1")
expect_equal(ada_get_hash(url), "#frag")
expect_equal(ada_get_protocol(url), "https:")
expect_equal(ada_get_domain(url), "example.org")
expect_equal(ada_get_basename(url), "https://example.org")
})

get_functions <- c(
ada_get_href, ada_get_username, ada_get_password, ada_get_host, ada_get_hostname, ada_get_port, ada_get_pathname,
ada_get_search, ada_get_hash, ada_get_protocol
ada_get_search, ada_get_hash, ada_get_protocol, ada_get_domain, ada_get_basename
)

test_that("invalid urls should return NA, #26", {
Expand Down

0 comments on commit 5987cf7

Please sign in to comment.