Skip to content

Commit

Permalink
Merge pull request #8 from jhudsl/url-fix
Browse files Browse the repository at this point in the history
Multiple minor fixes to ottr report-maker
  • Loading branch information
cansavvy authored Oct 20, 2022
2 parents f2c52a3 + 3473911 commit 73ec152
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 5 additions & 1 deletion scripts/spell-check.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ if (!dir.exists('check_reports')) {
}

# Read in dictionary
dictionary <- readLines(file.path(root_dir, 'resources', 'dictionary.txt'))
dict_file <- file.path(root_dir, 'resources', 'dictionary.txt')
dictionary <- readLines(dict_file)

# Make it alphabetical and only unique entries
writeLines(unique(sort(dictionary)), dict_file)

# Only declare `.Rmd` files but not the ones in the style-sets directory
files <- list.files(pattern = 'Rmd$', recursive = TRUE, full.names = TRUE)
Expand Down
6 changes: 4 additions & 2 deletions scripts/url-check.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ test_url <- function(url) {
}

get_urls <- function(file) {
message(paste("Testing URLs from file:", file))
# Read in a file and return the urls from it
content <- readLines(file)
content <- grep("http|com$|www", content, value = TRUE)
url_pattern <- "http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+"
urls <- stringr::str_extract(content, url_pattern)
if (length(urls) > 0 ){
urls <- gsub(")$|)\\.$", "", urls)
urls_status <- sapply(urls, test_url)
urls <- gsub(")$|)\\.$|,$", "", urls)
urls <- urls[!is.na(urls)]
urls_status <- parallel::mclapply(urls, test_url, mc.cores = 4)
url_df <- data.frame(urls, urls_status, file)
return(url_df)
}
Expand Down

0 comments on commit 73ec152

Please sign in to comment.