-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
1,007 additions
and
158 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,8 @@ data/ | |
.Rhistory | ||
docs | ||
inst/doc | ||
doc | ||
docs/ | ||
Meta | ||
Meta/ | ||
|
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,32 @@ | ||
#' Analyze Refined Finna Metadata | ||
#' | ||
#' Performs basic analysis on Finna metadata, summarizing the distribution of formats, years, and authors. | ||
#' | ||
#' @param metadata A tibble containing refined Finna metadata. | ||
#' @return A list of tibbles with summaries of formats, years, and authors. | ||
#' @import dplyr | ||
#' @export | ||
#' @examples | ||
#' library(finna) | ||
#' sibelius_data <- search_finna("sibelius") | ||
#' refined_data <- refine_metadata(sibelius_data) | ||
#' analyze_metadata(refined_data) | ||
#' | ||
analyze_metadata <- function(metadata) { | ||
format_distribution <- metadata %>% | ||
count(Formats, sort = TRUE) | ||
|
||
year_distribution <- metadata %>% | ||
filter(!is.na(Year)) %>% | ||
count(Year, sort = TRUE) | ||
|
||
author_distribution <- metadata %>% | ||
filter(!is.na(Author)) %>% | ||
count(Author, sort = TRUE) | ||
|
||
list( | ||
format_distribution = format_distribution, | ||
year_distribution = year_distribution, | ||
author_distribution = author_distribution | ||
) | ||
} |
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 |
---|---|---|
@@ -1,30 +1,37 @@ | ||
#' @title Check access to https://api.finna.fi/api/v1/?openapi | ||
#' @description Check if R has access to resources at https://api.finna.fi/api/v1/?openapi | ||
#' @description Check if R has access to resources at https://api.finna.fi/api/v1/?openapi. | ||
#' This function tests whether R can successfully connect to the Finna API by attempting to download from the API's OpenAPI specification. | ||
#' @export | ||
#' @return a logical. | ||
#' @return a logical indicating if the API is accessible (`TRUE`) or not (`FALSE`). | ||
#' | ||
#' @importFrom httr status_code | ||
#' @importFrom curl curl_download | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' check_api_access() | ||
#' } | ||
|
||
check_api_access <- function(){ | ||
#' \dontrun{ | ||
#' # Check if the API is accessible | ||
#' access <- check_api_access() | ||
#' if (access) { | ||
#' message("Finna API is accessible") | ||
#' } else { | ||
#' message("Finna API is not accessible") | ||
#' } | ||
#' } | ||
|
||
check_api_access <- function() { | ||
temp <- tempfile() | ||
http_url <- "https://api.finna.fi/api/v1/?openapi" | ||
|
||
suppressWarnings( | ||
try( | ||
curl::curl_download(http_url, temp, quiet = TRUE), | ||
silent = TRUE) | ||
silent = TRUE | ||
) | ||
) | ||
|
||
if (is.na(file.info(temp)$size)) { | ||
FALSE | ||
} | ||
else{ | ||
} else { | ||
TRUE | ||
} | ||
} |
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,28 @@ | ||
#' Integrate Finna Metadata with Another Dataset | ||
#' | ||
#' Merges Finna metadata with another dataset using a common key (e.g., "Title"). | ||
#' | ||
#' @param metadata1 A tibble containing refined Finna metadata. | ||
#' @param metadata2 A tibble containing another dataset to merge with the Finna metadata. | ||
#' @param key A string specifying the key to join by. Defaults to "Title". | ||
#' @return A tibble containing the merged dataset. | ||
#' @import dplyr | ||
#' @export | ||
#' @examples | ||
#' library(dplyr) | ||
#' finna_data <- search_finna("sibelius") | ||
#' | ||
#' # Example other dataset to merge with | ||
#' other_data <- tibble::tibble( | ||
#' Title = c("Sibelius Symphony No. 5", "Finlandia", "Valse Triste"), | ||
#' Rating = c(5, 4, 3) | ||
#' ) | ||
#' | ||
#' # Integrate the two datasets by "Title" | ||
#' integrated_data <- integrate_metadata(finna_data, other_data, key = "Title") | ||
#' print(integrated_data) | ||
integrate_metadata <- function(metadata1, metadata2, key = "Title") { | ||
# Perform a full join based on the specified key | ||
integrated <- full_join(metadata1, metadata2, by = key) | ||
return(integrated) | ||
} |
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,29 @@ | ||
#' Refine Finna Metadata | ||
#' | ||
#' Refines the Finna metadata tibble by keeping relevant fields and cleaning up missing values. | ||
#' | ||
#' @param data A tibble containing raw Finna metadata. | ||
#' @return A tibble with selected, cleaned metadata fields. | ||
#' @import dplyr | ||
#' @export | ||
#' @examples | ||
#' library(finna) | ||
#' sibelius_data <- search_finna("sibelius") | ||
#' refine_metadata(sibelius_data) | ||
#' | ||
refine_metadata <- function(data) { | ||
refined <- data %>% | ||
mutate( | ||
Title = if_else(is.na(Title), "Unknown Title", Title), | ||
Author = if_else(is.na(Author), "Unknown Author", Author), | ||
Year = if_else(is.na(Year), "Unknown Year", Year), | ||
Language = if_else(is.na(Language), "Unknown Language", Language), | ||
Formats = if_else(is.na(Formats), "Unknown Format", Formats), | ||
Subjects = if_else(is.na(Subjects), "Unknown Subjects", Subjects), | ||
Library = if_else(is.na(Library), "Unknown Library", Library), | ||
Series = if_else(is.na(Series), "Unknown Series", Series) | ||
) %>% | ||
select(Title, Author, Year, Language, Formats, Subjects, Library, Series) | ||
|
||
return(refined) | ||
} |
Oops, something went wrong.