Skip to content

See https://tools.ietf.org/html/rfc3986 for details of parsing algorithm.

Usage

parse_url(url)

build_url(url)

Arguments

url

For parse_url a character vector (of length 1) to parse into components; for build_url a list of components to turn back into a string.

Value

a list containing:

  • scheme

  • hostname

  • port

  • path

  • params

  • fragment

  • query, a list

  • username

  • password

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"