url_modify: Modifies a URL string by updating its components.

View source: R/RcppExports.R

url_modifyR Documentation

Modifies a URL string by updating its components.

Description

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.

Usage

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)

Arguments

url

A character string representing the original URL.

scheme

A character string for the new scheme (e.g., "http" or "https") or NULL to keep it unchanged.

user

A character string for the username or NULL to keep it unchanged.

password

A character string for the new password or NULL to keep it unchanged.

host

A character string for the new host or NULL to keep it unchanged.

port

A character string for the new port or NULL to keep it unchanged.

path

A character string for the new path or NULL to keep it unchanged.

query

A list or character of new query parameters or NULL to keep it unchanged.

fragment

A character string for the new fragment or NULL to keep it unchanged.

Value

A character string representing the modified URL.

Examples

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")


urlparse documentation built on April 15, 2025, 1:16 a.m.