Append to URL
append_to_url.Rd
Append one or more value(s) to a corresponding URL.
Arguments
- x
Value(s) to append, as a character vector.
- url
One or more URLs or URL names recognized by this package, as a character vector. If only one value is provided, it will be recycled; otherwise the length of
url
andx
must match. Seeget_url()
for recognized base URL names.- sep
One or more separators to use between
url
andx
, as a character vector. If only one value is provided (e.g. default = ""), it will be recycled; otherwise the length ofsep
andx
must match. If anyurl
ends in the correspondingsep
, an additionalsep
will not be added.
Examples
append_to_url("blah", "http://fake.url.com/")
#> [1] "http://fake.url.com/blah"
# separator can be specified and will not be duplicated
append_to_url("blah", "http://fake.url.com/", sep = "?q=")
#> [1] "http://fake.url.com/?q=blah"
append_to_url("blah", "http://fake.url.com/", sep = "/")
#> [1] "http://fake.url.com/blah"
# vectorized w/recycling
append_to_url(c("blah", "ugh"), "http://fake.url.com", sep = "/")
#> [1] "http://fake.url.com/blah" "http://fake.url.com/ugh"
append_to_url(
c("blah", "ugh"),
c("http://fake.url.com", "https://madeup.url.com/"),
sep = "/"
)
#> [1] "http://fake.url.com/blah" "https://madeup.url.com/ugh"
append_to_url(
c("blah", "ugh"),
c("http://fake.url.com", "https://madeup.url.com/"),
sep = c("/", "?q=")
)
#> [1] "http://fake.url.com/blah" "https://madeup.url.com/?q=ugh"
# missing values in `x` or `url` are preserved
append_to_url(
c(NA, "uhhh"),
c("http://fake.url.com", "https://this.is.it.com/"),
sep = "/"
)
#> [1] NA "https://this.is.it.com/uhhh"
append_to_url(
c(NA, "uhhh"),
c("http://fake.url.com", NA_character_),
c("=", NA)
)
#> [1] NA NA
# `sep` must not be missing for non-missing values of `x` and `url`
try(
append_to_url(
c(NA, "uhhh"),
c("http://fake.url.com", "https://this.is.it.com/"),
sep = c("/", NA)
)
)
#> Error in purrr::pmap_chr(list(url, x, sep, ignore_sep), function(.u, .x, :
#> ℹ In index: 2.
#> Caused by error in `paste()`:
#> ! invalid separator