Skip to content

Commit 315300e

Browse files
Make check_ip() and exclude_ip() examples interactive
1 parent 4f58c2c commit 315300e

File tree

3 files changed

+50
-33
lines changed

3 files changed

+50
-33
lines changed

R/ip.R

Lines changed: 46 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,16 @@
6464
#' df <- qualtrics_text %>%
6565
#' exclude_preview() %>%
6666
#' mark_ip(country = "DE")
67-
mark_ip <- function(x,
68-
id_col = "ResponseId",
69-
ip_col = "IPAddress",
70-
rename = TRUE,
71-
country = "US",
72-
include_na = FALSE,
73-
quiet = FALSE,
74-
print = TRUE) {
67+
mark_ip <- function(
68+
x,
69+
id_col = "ResponseId",
70+
ip_col = "IPAddress",
71+
rename = TRUE,
72+
country = "US",
73+
include_na = FALSE,
74+
quiet = FALSE,
75+
print = TRUE
76+
) {
7577
# Rename columns
7678
if (rename) {
7779
x <- rename_columns(x, alert = FALSE)
@@ -114,10 +116,14 @@ mark_ip <- function(x,
114116
cli::cli_alert_warning("There is no internet connection.")
115117
return(invisible(NULL))
116118
} else if (identical(country_ip_ranges, NA)) {
117-
cli::cli_alert_warning("The website for downloading country IP addresses is not available. Please try again later.")
119+
cli::cli_alert_warning(
120+
"The website for downloading country IP addresses is not available. Please try again later."
121+
)
118122
return(invisible(NULL))
119123
} else if (identical(country_ip_ranges, NULL)) {
120-
cli::cli_alert_warning("'{country}' is not recognized as a valid country code, so IP addresses could not be checked for this country.")
124+
cli::cli_alert_warning(
125+
"'{country}' is not recognized as a valid country code, so IP addresses could not be checked for this country."
126+
)
121127
return(invisible(NULL))
122128
} else {
123129
# Filter data based on IP ranges
@@ -191,7 +197,7 @@ mark_ip <- function(x,
191197
#' per session, as it caches the results for future work during the session.
192198
#'
193199
#' @export
194-
#' @examples
200+
#' @examplesIf interactive()
195201
#' # Check for IP addresses outside of the US
196202
#' data(qualtrics_text)
197203
#' check_ip(qualtrics_text)
@@ -215,17 +221,20 @@ mark_ip <- function(x,
215221
#' qualtrics_text %>%
216222
#' exclude_preview() %>%
217223
#' check_ip(quiet = TRUE)
218-
check_ip <- function(x,
219-
id_col = "ResponseId",
220-
ip_col = "IPAddress",
221-
rename = TRUE,
222-
country = "US",
223-
include_na = FALSE,
224-
keep = FALSE,
225-
quiet = FALSE,
226-
print = TRUE) {
224+
check_ip <- function(
225+
x,
226+
id_col = "ResponseId",
227+
ip_col = "IPAddress",
228+
rename = TRUE,
229+
country = "US",
230+
include_na = FALSE,
231+
keep = FALSE,
232+
quiet = FALSE,
233+
print = TRUE
234+
) {
227235
# Mark and filter ip
228-
exclusions <- mark_ip(x,
236+
exclusions <- mark_ip(
237+
x,
229238
id_col = id_col,
230239
ip_col = ip_col,
231240
rename = rename,
@@ -269,7 +278,7 @@ check_ip <- function(x,
269278
#'
270279
#' @export
271280
#'
272-
#' @examples
281+
#' @examplesIf interactive()
273282
#' # Exclude IP addresses outside of the US
274283
#' data(qualtrics_text)
275284
#' df <- exclude_ip(qualtrics_text)
@@ -283,17 +292,20 @@ check_ip <- function(x,
283292
#' df <- qualtrics_text %>%
284293
#' exclude_preview() %>%
285294
#' exclude_ip(country = "DE")
286-
exclude_ip <- function(x,
287-
id_col = "ResponseId",
288-
ip_col = "IPAddress",
289-
rename = TRUE,
290-
country = "US",
291-
include_na = FALSE,
292-
quiet = TRUE,
293-
print = TRUE,
294-
silent = FALSE) {
295+
exclude_ip <- function(
296+
x,
297+
id_col = "ResponseId",
298+
ip_col = "IPAddress",
299+
rename = TRUE,
300+
country = "US",
301+
include_na = FALSE,
302+
quiet = TRUE,
303+
print = TRUE,
304+
silent = FALSE
305+
) {
295306
# Mark and filter ip
296-
remaining_data <- mark_ip(x,
307+
remaining_data <- mark_ip(
308+
x,
297309
id_col = id_col,
298310
ip_col = ip_col,
299311
rename = rename,
@@ -307,7 +319,8 @@ exclude_ip <- function(x,
307319
# Print exclusion statement
308320
if (identical(silent, FALSE)) {
309321
print_exclusion(
310-
remaining_data, x,
322+
remaining_data,
323+
x,
311324
paste0("rows with IP addresses outside of ", country)
312325
)
313326
}

man/check_ip.Rd

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/exclude_ip.Rd

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)