url_modify | R Documentation |
This function modifies a URL string by updating its components such as scheme, user, password, host, port, query, raw query, and fragment.
If any of these components are not provided (i.e., NULL
), the existing components of the URL are retained.
url_modify(
url,
scheme = NULL,
user = NULL,
password = NULL,
host = NULL,
port = NULL,
path = NULL,
query = NULL,
fragment = NULL
)
set_scheme(url, scheme)
set_user(url, user)
set_password(url, password)
set_host(url, host)
set_port(url, port)
set_path(url, path)
set_query(url, query)
set_fragment(url, fragment)
url |
A character string representing the original URL. |
scheme |
A character string for the new scheme (e.g., "http" or "https") or |
user |
A character string for the username or |
password |
A character string for the new password or |
host |
A character string for the new host or |
port |
A character string for the new port or |
path |
A character string for the new path or |
query |
A list or character of new query parameters or |
fragment |
A character string for the new fragment or |
A character string representing the modified URL.
library(urlparse)
# Example 1: Modify the scheme and host of a URL
url_modify(
"https://user:pass@host.com/path?query#fragment",
scheme = "http",
host = "example.com"
)
# Example 2: Add a query parameter to a URL
url_modify(
"https://host.com/path", query = list(key1 = "value1", key2 = "value2")
)
# Example 3: Change the fragment of a URL
url_modify("https://host.com/path#old_fragment", fragment = "new_fragment")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.