urltools (version 0.6)

replace_parameter: replace the value of an API parameter

Description

replace_parameter takes a vector of URLs and replaces the value associated with a particular URL parameter, with one of your choosing.

Usage

replace_parameter(urls, parameter, new_value)

Arguments

urls
a vector of URLs.
parameter
the name of the parameter to search for. Case sensitive (so preprocessing with tolower may be useful).
new_value
the value you want to replace the current value of parameter.

Value

  • a character vector containing the amended URLs. In the situation where the parameter is not present within the URL, the original URL will be returned.

Details

As well as component extraction, people can also find it useful to have access to component replacement - for example, mass-modifying a set of URLs used for API queries to output JSON rather than XML.

replace_parameter accepts a vector of URLs, the name of a parameter, and a replacement value. It then loops through the URLs replacing the existing value held by that parameter with the new one.

In the case that a parameter is present multiple times in a URL, only the first instance will be amended. In the case that a parameter is not present at all, no change to the URL will be made.

See Also

extract_parameter for extracting, rather than replacing, values.

Examples

Run this code
replace_parameter(urls = "http://google.org/api.php?smstate=all",
                 parameter = "smstate", new_value = "some")

Run the code above in your browser using DataLab