64
64
# ' df <- qualtrics_text %>%
65
65
# ' exclude_preview() %>%
66
66
# ' 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
+ ) {
75
77
# Rename columns
76
78
if (rename ) {
77
79
x <- rename_columns(x , alert = FALSE )
@@ -114,10 +116,14 @@ mark_ip <- function(x,
114
116
cli :: cli_alert_warning(" There is no internet connection." )
115
117
return (invisible (NULL ))
116
118
} 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
+ )
118
122
return (invisible (NULL ))
119
123
} 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
+ )
121
127
return (invisible (NULL ))
122
128
} else {
123
129
# Filter data based on IP ranges
@@ -191,7 +197,7 @@ mark_ip <- function(x,
191
197
# ' per session, as it caches the results for future work during the session.
192
198
# '
193
199
# ' @export
194
- # ' @examples
200
+ # ' @examplesIf interactive()
195
201
# ' # Check for IP addresses outside of the US
196
202
# ' data(qualtrics_text)
197
203
# ' check_ip(qualtrics_text)
@@ -215,17 +221,20 @@ mark_ip <- function(x,
215
221
# ' qualtrics_text %>%
216
222
# ' exclude_preview() %>%
217
223
# ' 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
+ ) {
227
235
# Mark and filter ip
228
- exclusions <- mark_ip(x ,
236
+ exclusions <- mark_ip(
237
+ x ,
229
238
id_col = id_col ,
230
239
ip_col = ip_col ,
231
240
rename = rename ,
@@ -269,7 +278,7 @@ check_ip <- function(x,
269
278
# '
270
279
# ' @export
271
280
# '
272
- # ' @examples
281
+ # ' @examplesIf interactive()
273
282
# ' # Exclude IP addresses outside of the US
274
283
# ' data(qualtrics_text)
275
284
# ' df <- exclude_ip(qualtrics_text)
@@ -283,17 +292,20 @@ check_ip <- function(x,
283
292
# ' df <- qualtrics_text %>%
284
293
# ' exclude_preview() %>%
285
294
# ' 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
+ ) {
295
306
# Mark and filter ip
296
- remaining_data <- mark_ip(x ,
307
+ remaining_data <- mark_ip(
308
+ x ,
297
309
id_col = id_col ,
298
310
ip_col = ip_col ,
299
311
rename = rename ,
@@ -307,7 +319,8 @@ exclude_ip <- function(x,
307
319
# Print exclusion statement
308
320
if (identical(silent , FALSE )) {
309
321
print_exclusion(
310
- remaining_data , x ,
322
+ remaining_data ,
323
+ x ,
311
324
paste0(" rows with IP addresses outside of " , country )
312
325
)
313
326
}
0 commit comments