Extracts the path component of a URL.
Usage
get_path(
url,
protocol_handling = "keep",
case_handling = c("lower_host", "keep", "lower", "upper"),
trailing_slash_handling = c("none", "keep", "strip"),
index_page_handling = c("keep", "strip"),
path_normalization = c("none", "collapse_slashes", "dot_segments", "both"),
path_encoding = c("keep", "encode", "decode"),
scheme_policy = c("infer", "require"),
scheme_acceptance = c("web", "general"),
url_standard = NULL
)Arguments
- url
A character vector of URLs.
- protocol_handling
A character string specifying how to handle protocols. Defaults to "keep". Regardless of this option, rurl only processes authority-based URLs whose scheme is one of http, https, ftp, or ftps; a scheme-bearing input with any other scheme (e.g.
mailto:,tel:,ws:) yieldsparse_status = "error". Scheme inference (below) also requires the input to be host-shaped: a scheme-less string that is not a host (e.g."asdfghjkl","12345","/path") or is a non-canonical IP literal (integer/hex/octal/short forms, or leading-zero octets like"192.168.010.1") is rejected as"error"rather than having a scheme fabricated for it."keep": If a supported scheme exists (http, https, ftp, ftps), it's used. If no scheme and the input is host-shaped, "http://" is added; otherwise the input is not a URL and yields
"error"."none": If a supported scheme exists, it's used. If no scheme, then no scheme is used (scheme component will be NA).
"strip": Any existing scheme is removed (scheme component will be NA).
"http": The scheme is forced to be "http".
"https": The scheme is forced to be "https".
- case_handling
How to handle casing of the returned path. Defaults to "lower_host", which preserves the path's original casing (paths are case-sensitive per RFC 3986 §6.2.2.1). Use "lower"/"upper" to force a case.
- trailing_slash_handling
A character string specifying how to handle trailing slashes in the path component of the cleaned URL. Defaults to "none".
"none": (Default) No specific handling is applied. Path remains as is after initial parsing.
"keep": Ensures a trailing slash. If a path exists and doesn't end with one, it's added. If path is just "/", it's kept.
"strip": Removes a trailing slash if present, unless the path is solely "/".
- index_page_handling
A character string specifying how to handle index/default pages. Defaults to "keep".
"keep": (Default) Leave index/default page segments untouched.
"strip": Remove a trailing index.* or default.* segment (case-insensitive).
- path_normalization
How to normalize path structure. Defaults to "none". rurl owns dot-segment resolution: the path is read from the input verbatim (not from libcurl's pre-normalized path), so
"none"preserves./..segments (/a/../bstays/a/../b) and only the settings below change them. Resolution follows RFC 3986 section 5.2.4 and acts on literal./..segments only — a percent-encoded%2eis a normal path byte, never a dot segment, so it is never treated as traversal."none": (Default) No normalization; dot and slash structure is preserved exactly as written.
"collapse_slashes": Collapse duplicate slashes in the path.
"dot_segments": Resolve . and .. segments per RFC 3986.
"both": Apply both collapse_slashes and dot_segments.
- path_encoding
How to present the path percent-encoding in
clean_url— the readable-vs-browser rendering choice (the path analog ofhost_encoding). Defaults to "keep". This is an orthogonal presentation knob: it is independent ofurl_standardand layers on top of any profile (e.g.url_standard = "whatwg", path_encoding = "encode"emits the WHATWG-parsed path in browser form), exactly likehost_encoding. Only "keep" preserves a profile's canonical identity path verbatim; "encode" and "decode" are presentation forms that may re-encode or decode reserved octets (so%2Fmay fold to a path-separating/), independent of whether a profile is set."keep": Leave the path percent-encoding untouched (the path is preserved as written in the URL, so
%2Fstays%2Frather than decoding into a path-separating/). With nourl_standard, rurl keeps its historical RFC-style percent-hex case canonicalization, so%2fbecomes%2F. Underurl_standard = "whatwg", existing percent-triplet spelling is preserved byte-for-byte. Use "encode" to additionally normalize which bytes are encoded."encode": The browser/percent-encoded rendering. Decodes the path first, then percent-encodes each segment (slashes preserved), so a readable non-ASCII path is emitted in its percent-encoded UTF-8 form.
"decode": The readable rendering. Percent-decodes UTF-8 sequences in the path, so a percent-encoded segment is shown as readable text.
- scheme_policy
Controls whether scheme-less, host-shaped input is accepted (an input-acceptance axis, distinct from
protocol_handling, which only controls how the scheme is presented, and fromurl_standard, which controls interpretation). Defaults to "infer"."infer": (Default) Fabricate
http://for scheme-less host-shaped input (e.g.example.comparses ashttp://example.com), a browser-omnibox-style affordance. This is the historical behavior."require": Reject scheme-less input — a scheme-less host-shaped value becomes
parse_status = "error"rather than gaining a fabricated scheme. Use this for a strict, pure-parser posture. Note this governs only bare host input; scheme-relative//hostinput is governed separately byscheme_relative_handling.
- scheme_acceptance
Which scheme tokens may enter parsing (a scheme-acceptance axis, distinct from
scheme_policy, which governs scheme-less input, and fromurl_standard, which governs interpretation). Defaults to "web"."web": (Default) Only the curated web-scheme allowlist (
http/https/ftp/ftps/file) is admitted; a scheme-bearing input outside it isparse_status = "error". This is the historical, byte-for-byte compatible behavior."general": Admit any syntactically valid scheme token and parse opaque (
mailto:x), non-special (foo://host), and RFC-generic URLs. Requires an expliciturl_standard("rfc3986"or"whatwg"), which decides the interpretation;generalwithurl_standard = NULLis an error. Non-special / opaque hosts receive no www-stripping, no domain/TLD derivation, and are never run through the IDNA/punycode helpers. A non-special scheme with no//is an opaque path: it has no authority, sohost,user,portand thedomain/tldcolumns are allNAand the entire remainder is thepath(query/fragmentare still split off). This includesmailto:— the recipient's@never re-triggers authority parsing. To decompose amailto:recipient, use the accessors (get_host()/get_domain()/get_user(), ADR 0012 D7) orget_mailto_recipients(); those deliberately return a recipient's parts where this table presentsNA, because a recipient domain is extraction metadata, not the URL's authority.
- url_standard
Optional top-level standard profile:
NULL(default),"rfc3986", or"whatwg". WithNULLthe behavior is exactly what the individual low-level options select (fully backward compatible). When set, it selects a coherent set of standard-conformant behaviors for the axes it governs — path percent/dot handling, the host IPv4/reg-name model, andcase_handling— so callers do not have to hand-assemble the low-level knobs. Passing a governed low-level knob (path_normalizationorcase_handling) with a value the selected profile would not choose is an error; passing the value the profile would pick is accepted (onlycase_handling = "lower_host"is accepted under a selector —"keep","lower", and"upper"all conflict, since"lower"also lowercases the path, which neither standard sanctions). Added as the last argument so existing positional calls keep their meaning; always pass it by name. Under"whatwg"the selector additionally recognizes a literal backslash as a path separator for WHATWG-special schemes (http/https/ftp) and nulls default ports in parse output; useport_handling = "strip_default"for spec-style clean URL port rendering. Seeresolve_urlforurl_standard-governed reference resolution. The selector does not govern whetherport_handlingmay be set (it is a standalone editorial knob), nor does it governpath_encoding(an orthogonal path-presentation knob that layers on any profile), IDNA rendering, or query handling.