See https://www.rfc-editor.org/rfc/rfc3986 for details of parsing algorithm.
Arguments
- url
For
parse_url
a character vector (of length 1) to parse into components; forbuild_url
a list of components to turn back into a string.
Examples
parse_url("http://google.com/")
#> $scheme
#> [1] "http"
#>
#> $hostname
#> [1] "google.com"
#>
#> $port
#> NULL
#>
#> $path
#> [1] ""
#>
#> $query
#> NULL
#>
#> $params
#> NULL
#>
#> $fragment
#> NULL
#>
#> $username
#> NULL
#>
#> $password
#> NULL
#>
#> attr(,"class")
#> [1] "url"
parse_url("http://google.com:80/")
#> $scheme
#> [1] "http"
#>
#> $hostname
#> [1] "google.com"
#>
#> $port
#> [1] "80"
#>
#> $path
#> [1] ""
#>
#> $query
#> NULL
#>
#> $params
#> NULL
#>
#> $fragment
#> NULL
#>
#> $username
#> NULL
#>
#> $password
#> NULL
#>
#> attr(,"class")
#> [1] "url"
parse_url("http://google.com:80/?a=1&b=2")
#> $scheme
#> [1] "http"
#>
#> $hostname
#> [1] "google.com"
#>
#> $port
#> [1] "80"
#>
#> $path
#> [1] ""
#>
#> $query
#> $query$a
#> [1] "1"
#>
#> $query$b
#> [1] "2"
#>
#>
#> $params
#> NULL
#>
#> $fragment
#> NULL
#>
#> $username
#> NULL
#>
#> $password
#> NULL
#>
#> attr(,"class")
#> [1] "url"
url <- parse_url("http://google.com/")
url$scheme <- "https"
url$query <- list(q = "hello")
build_url(url)
#> [1] "https://google.com/?q=hello"