ropensci / handlr

convert among citation formats
https://docs.ropensci.org/handlr
Other
38 stars 4 forks source link

Error in `ris_reader()` for files with more than one abstract #35

Open JsLth opened 1 year ago

JsLth commented 1 year ago

For RIS files with multiple abstracts the ris_reader() function aborts with the following error message:

> handlr::ris_reader("example.ris")
Error in if (!nchar(grep("^AB|^N2", x, value = TRUE)) > 200) { : 
  the condition has length > 1

My example RIS looks like this (as exported by Zotero):

TY  - JOUR
TI  - Energy Poverty in Europe: A Multidimensional Approach
AU  - Bollino, Carlo Andrea
AU  - Botti, Fabrizio
T2  - PSL Quarterly Review
AB  - With the European Commission’s “Third Energy Package”, the challenges posed by energy poverty have been recently acknowledged by European legislation.  The paper develops a synthetic indicator of energy poverty for the purpose of assessing households’ well-being across different domains of inequality in access to energy services and to a healthy domestic environment. These dimensions are broadly defined in terms of energy affordability and thermal efficiency, two of the main manifestations of energy poverty. The analysis focuses on Europe and expands on existing economic literature by employing a fuzzy analysis for the definition of a multidimensional energy poverty index, which is then used to investigate the role of individual and household characteristics in shaping energy poverty. We find that during the European crisis energy poverty has been more stable than monetary poverty, and that thermal efficiency plays a crucial role in shaping individual and countries’ average degrees of energy poverty. 

JEL codes: I32; Q41; D10; D63
DA  - 2017/12/04/
PY  - 2017
DO  - 10.13133/2037-3643_70.283_4
DP  - DOI.org (Datacite)
VL  - V. 70
SP  - 473
EP  - 507 Paginazione
LA  - en
ST  - Energy Poverty in Europe
UR  - https://ojs.uniroma1.it/index.php/PSLQuarterlyReview/article/view/14155
Y2  - 2023/05/09/13:08:44
KW  - Energy Poverty, Fuel Poverty, Multidimensional Poverty, Fuzzy Analysis
KW  - I32; Q41; D10; D63
ER  - 

TY  - JOUR
TI  - The energy divide: Integrating energy transitions, regional inequalities and poverty trends in the European Union
AU  - Bouzarovski, Stefan
AU  - Tirado Herrero, Sergio
T2  - European Urban and Regional Studies
AB  - Energy poverty can be understood as the inability of a household to secure a socially and materially necessitated level of energy services in the home. While the condition is widespread across Europe, its spatial and social distribution is highly uneven. In this paper, the existence of a geographical energy poverty divide in the European Union (EU) provides a starting point for conceptualizing and exploring the relationship between energy transitions – commonly described as wide-ranging processes of socio-technical change – and existing patterns of regional economic inequality. We have undertaken a comprehensive analysis of spatial and temporal trends in the national-scale patterns of energy poverty, as well as gas and electricity prices. The results of our work indicate that the classic economic development distinction between the core and periphery also holds true in the case of energy poverty, as the incidence of this phenomenon is significantly higher in Southern and Eastern European EU Member States. The paper thus aims to provide the building blocks for a novel theoretical integration of questions of path-dependency, uneven development and material deprivation in existing interpretations of energy transitions.
DA  - 2017/01//
PY  - 2017
DO  - 10.1177/0969776415596449
DP  - DOI.org (Crossref)
VL  - 24
IS  - 1
SP  - 69
EP  - 86
J2  - European Urban and Regional Studies
LA  - en
SN  - 0969-7764, 1461-7145
ST  - The energy divide
UR  - http://journals.sagepub.com/doi/10.1177/0969776415596449
Y2  - 2023/05/09/13:08:56
L1  - https://europepmc.org/articles/pmc5477826?pdf=render
ER  - 

If I remove abstracts beforehand, the error does not occur:

clean_ris <- function(file) {
  ris <- readLines(file, encoding = "UTF-8")
  ris <- paste(ris[!grepl("^AB|^N2", ris)], collapse = "\n")
  cat(ris, "\n", file = file)
  file
}

handlr::ris_reader(clean_ris("example.ris"))

It seems like this issue relates to the fact that when multiple abstracts are found, the if condition to determine abstract length (Line 113 in ris_reader.R) is not valid. My workaround is to add a call to any() to ensure that a single logical value is passed to if:

if (!any(nchar(grep("^AB|^N2", x, value = TRUE)) > 200))

I don't know if this is a reliable fix or if it introduces issues down the line, but in the case of my example RIS, it seems to work.