The mark_ip()
function creates a column labeling
rows of data that have IP addresses from outside the specified country.
The function is written to work with data from
Qualtrics surveys.
Usage
mark_ip(
x,
id_col = "ResponseId",
ip_col = "IPAddress",
rename = TRUE,
country = "US",
include_na = FALSE,
quiet = FALSE,
print = TRUE
)
Arguments
- x
Data frame or tibble (preferably imported from Qualtrics using {qualtRics}).
- id_col
Column name for unique row ID (e.g., participant).
- ip_col
Column name for IP addresses.
- rename
Logical indicating whether to rename columns (using
rename_columns()
)- country
Two-letter abbreviation of country to check (default is "US").
- include_na
Logical indicating whether to include rows with NA in IP address column in the output list of potentially excluded data.
- quiet
Logical indicating whether to print message to console.
Logical indicating whether to print returned tibble to console.
Value
An object of the same type as x
that includes a column marking rows
with IP addresses outside of the specified country.
For a function that checks these rows, use check_ip()
.
For a function that excludes these rows, use exclude_ip()
.
Details
To record this information in your Qualtrics survey, you must ensure that Anonymize responses is disabled.
Default column names are set based on output from the
qualtRics::fetch_survey()
.
The function uses ipaddress::country_networks()
to assign IP addresses to
specific countries using
ISO 3166-1 alpha-2 country codes.
The function outputs to console a message about the number of rows
with IP addresses outside of the specified country. If there are NA
s for IP
addresses (likely due to including preview data—see check_preview()
), it
will print a message alerting to the number of rows with NA
s.
Note
This function requires internet connectivity as it uses the
ipaddress::country_networks()
function, which pulls daily updated data
from https://www.iwik.org/ipcountry/. It only updates the data once
per session, as it caches the results for future work during the session.
See also
Other ip functions:
check_ip()
,
exclude_ip()
Other mark functions:
mark_duplicates()
,
mark_duration()
,
mark_location()
,
mark_preview()
,
mark_progress()
,
mark_resolution()
Examples
# Mark IP addresses outside of the US
data(qualtrics_text)
df <- mark_ip(qualtrics_text)
#> ℹ 2 out of 100 rows had NA values for IP addresses (check for preview data with 'check_preview()').
#> ℹ 12 out of 100 rows had IP address outside of US.
# Remove preview data first
df <- qualtrics_text %>%
exclude_preview() %>%
mark_ip()
#> ℹ 2 out of 100 preview rows were excluded, leaving 98 rows.
#> ℹ 12 out of 98 rows had IP address outside of US.
# Mark IP addresses outside of Germany
df <- qualtrics_text %>%
exclude_preview() %>%
mark_ip(country = "DE")
#> ℹ 2 out of 100 preview rows were excluded, leaving 98 rows.
#> ℹ 94 out of 98 rows had IP address outside of DE.