Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
michalovadek authored Jul 26, 2021
1 parent 0e2c771 commit 92f8fac
Show file tree
Hide file tree
Showing 27 changed files with 213 additions and 83 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: eurlex
Type: Package
Title: Retrieve Data on European Union Law
Version: 0.3.5
Version: 0.3.6
Authors@R: c(person(given = "Michal",
family = "Ovadek",
role = c("aut", "cre", "cph"),
Expand All @@ -10,7 +10,6 @@ Authors@R: c(person(given = "Michal",
Description: Access to data on European Union laws and court decisions made easy with pre-defined 'SPARQL' queries and 'GET' requests.
License: GPL-3
Encoding: UTF-8
LazyData: true
Depends:
R (>= 3.4.0)
Imports:
Expand All @@ -19,6 +18,7 @@ Imports:
xml2,
tidyr,
httr,
curl,
rvest,
rlang,
stringr,
Expand Down
11 changes: 11 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# eurlex 0.3.6

## Major changes

- `elx_run_query()` now fails gracefully in presence of internet/server problems
- `elx_fetch_data()` now automatically fixes urls with parentheses (e.g. "32019H1115(01)" used to fail)

## Minor changes

- minor fixes to vignette

# eurlex 0.3.5

## Major changes
Expand Down
3 changes: 2 additions & 1 deletion R/elx_curia_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
#' @param parse If `TRUE`, references to cases and appeals are parsed out from `case_info` into separate columns
#' @return
#' A data frame containing case identifiers and information as character columns. Where the case id
#' contains a hyperlink to Eur-Lex, the CELEX identifier is retrieved as well.
#' contains a hyperlink to Eur-Lex, the CELEX identifier is retrieved as well. Hyperlinks to Eur-Lex
#' disappeared from more recent cases.
#' @importFrom rlang .data
#' @export
#' @examples
Expand Down
13 changes: 13 additions & 0 deletions R/elx_fetch_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ elx_fetch_data <- function(url, type = c("title","text","ids"),

language <- paste(language_1,", ",language_2,";q=0.8, ",language_3,";q=0.7", sep = "")

if (stringr::str_detect(url,"celex")){

clx <- stringr::str_extract(url, "(?<=celex\\/).*") %>%
stringr::str_replace_all("\\(","%28") %>%
stringr::str_replace_all("\\)","%29") %>%
stringr::str_replace_all("\\/","%2F")

url <- paste("http://publications.europa.eu/resource/celex/",
clx,
sep = "")

}

if (type == "title"){

response <- httr::GET(url=url,
Expand Down
50 changes: 47 additions & 3 deletions R/elx_run_query.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ elx_run_query <- function(query = "", endpoint = "http://publications.europa.eu/

curlready <- paste(endpoint,"?query=",gsub("\\+","%2B", utils::URLencode(query, reserved = TRUE)), sep = "")

sparql_response <- httr::GET(url = curlready,
httr::add_headers('Accept' = 'application/sparql-results+xml')
)
sparql_response <- graceful_http(curlready)

sparql_response_parsed <- sparql_response %>%
elx_parse_xml()
Expand All @@ -31,3 +29,49 @@ elx_run_query <- function(query = "", endpoint = "http://publications.europa.eu/

}

#' Fail http call gracefully
#'
#' @importFrom rlang .data
#'
#' @noRd
#'

graceful_http <- function(remote_file) {

try_GET <- function(x, ...) {
tryCatch(
httr::GET(url = x,
#httr::timeout(1000000000),
httr::add_headers('Accept' = 'application/sparql-results+xml')),
error = function(e) conditionMessage(e),
warning = function(w) conditionMessage(w)
)
}

is_response <- function(x) {
class(x) == "response"
}

# First check internet connection
if (!curl::has_internet()) {
message("No internet connection.")
return(invisible(NULL))
}

# Then try for timeout problems
resp <- try_GET(remote_file)
if (!is_response(resp)) {
message(resp)
return(invisible(NULL))
}

# Then stop if status > 400
if (httr::http_error(resp)) {
httr::message_for_status(resp)
return(invisible(NULL))
}

return(resp)

}

6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ Please consider contributing to the maintanance and development of the package b

## Latest changes

### eurlex 0.3.6

- `elx_run_query()` now fails gracefully in presence of internet/server problems
- `elx_fetch_data()` now automatically fixes urls with parentheses (e.g. "32019H1115(01)" used to fail)
- minor fixes to vignette

### eurlex 0.3.5

- it is now possible to select all resource types available with `elx_make_query(resource_type = "any")`. Since there are nearly 1 million CELEX codes, use with discretion and expect long execution times
Expand Down
26 changes: 13 additions & 13 deletions doc/eurlexpkg.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/404.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions docs/articles/eurlexpkg.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified docs/articles/eurlexpkg_files/figure-html/firstplot-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/articles/eurlexpkg_files/figure-html/unnamed-chunk-9-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/articles/eurlexpkg_files/figure-html/wordcloud-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/articles/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/authors.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion docs/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 92f8fac

Please sign in to comment.