The exclude_ip()
function removes rows of data that have
IP addresses from outside the specified country.
The function is written to work with data from
Qualtrics surveys.
Usage
exclude_ip(
x,
id_col = "ResponseId",
ip_col = "IPAddress",
rename = TRUE,
country = "US",
include_na = FALSE,
quiet = TRUE,
print = TRUE,
silent = FALSE
)
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.
- silent
Logical indicating whether to print message to console. Note this argument controls the exclude message not the check message.
Value
An object of the same type as x
that excludes rows
with IP addresses outside of the specified country.
For a function that checks these rows, use check_ip()
.
For a function that marks these rows, use mark_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 http://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()
,
mark_ip()
Other exclude functions:
exclude_duplicates()
,
exclude_duration()
,
exclude_location()
,
exclude_preview()
,
exclude_progress()
,
exclude_resolution()
Examples
# Exclude IP addresses outside of the US
data(qualtrics_text)
df <- exclude_ip(qualtrics_text)
#> ℹ 12 out of 100 rows with IP addresses outside of US were excluded, leaving 88 rows.
# Remove preview data first
df <- qualtrics_text %>%
exclude_preview() %>%
exclude_ip()
#> ℹ 2 out of 100 preview rows were excluded, leaving 98 rows.
#> ℹ 12 out of 98 rows with IP addresses outside of US were excluded, leaving 86 rows.
# Exclude IP addresses outside of Germany
df <- qualtrics_text %>%
exclude_preview() %>%
exclude_ip(country = "DE")
#> ℹ 2 out of 100 preview rows were excluded, leaving 98 rows.
#> ℹ 94 out of 98 rows with IP addresses outside of DE were excluded, leaving 4 rows.