-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from spsanderson/development
Fixes #102
- Loading branch information
Showing
4 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#' Check if a URL is valid | ||
#' | ||
#' @family Utility | ||
#' | ||
#' @author Steven P. Sanderson II, MPH | ||
#' | ||
#' @details The function uses the `httr2::url_parse` function to parse the URL | ||
#' and checks if the parsed URL contains a scheme and a hostname. If either | ||
#' is missing, the URL is considered invalid. | ||
#' | ||
#' @description | ||
#' This function validates a URL by checking the presence of a scheme and a | ||
#' hostname in the parsed URL. | ||
#' | ||
#' @param .url A character string representing the URL to be checked. | ||
#' | ||
#' @return A logical value: `TRUE` if the URL is valid, `FALSE` otherwise. | ||
#' | ||
#' @examples | ||
#' is_valid_url("https://www.example.com") # TRUE | ||
#' is_valid_url("not_a_url") # FALSE | ||
#' | ||
#' @name is_valid_url | ||
NULL | ||
|
||
#' @rdname is_valid_url | ||
#' @export | ||
is_valid_url <- function(url) { | ||
parsed_url <- httr2::url_parse(url) | ||
# Check if the parsed URL has a scheme and a host | ||
if (is.null(parsed_url$scheme) || is.null(parsed_url$hostname)) { | ||
return(FALSE) | ||
} else { | ||
return(TRUE) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.