Как я могу заставить эту функцию правильно добавлять записи для специальных символов, которые были преобразованы в странную форму? - PullRequest
0 голосов
/ 15 октября 2019

Я хочу экспортировать записи Mendeley, чтобы преуспеть, используя R, но я столкнулся с проблемами, потому что Mendeley неправильно экспортирует специальные символы, такие как ö и é, а используемый мной R-пакет, похоже, импортирует их как еще более странные символы.

В Mendeley я экспортирую источники в виде записей Bibtex. Когда они содержат специальный символ, такой как ö, он экспортируется как {\ "{o}}. Затем я использую R для импорта этих записей в фрейм данных.

Это содержимое файла bibtex, которым я являюсьиспользуя в этом примере:

@article{Kroger2016,
abstract = {With the rise of ‘bioeconomy', trees are receiving increasing attention. This contribution conducts a preliminary analysis of the trajectories and the main drivers of change in the rise of new, flexible and multiple uses of trees. It assesses the political dimensions involved in this transformation, which is simultaneously ongoing, anticipated and imagined. Notes are offered on the issues to be considered when the flex-crop framework is operationalized to include the study of trees, and additional conceptualizations that help in analyzing the political economy of tree uses are provided. Areas needing further empirical study are identified and a preliminary research agenda is suggested. The flexible and multiple use of trees and tree-derived commodities is having a large impact on power relations in the global political economy of forestry and the forest industry, the asymmetry of which is based on who is best able to flex or de-multiply, thereby controlling commodity webs and processing technology. It is argued that while flexing seems to increase diversity, in practice it typically increases this only for the processing industry; the converse occurs in terms of the unification of the productive base into monocultures. However, these two processes go hand in hand, and illustrate how flexing is a deeply capitalist process.},
annote = {My notes bla bla},
author = {Kr{\"{o}}ger, Markus},
doi = {10.1080/03066150.2016.1140646},
isbn = {0306-6150, 1743-9361},
issn = {17439361},
journal = {Journal of Peasant Studies},
keywords = {GM trees,capitalism,carbon sinks,commoditization,flex crops,flex tree plantations (FTPs),flex trees,forest futures,global forestry,green economy,wood products,wood-based energy,‘forest biorefineries'},
language = {en},
mendeley-groups = {Flex crops master thesis/Flex crops},
mendeley-tags = {flex crops},
number = {4},
pages = {886--909},
shorttitle = {The political economy of ‘flex trees'},
title = {{The political economy of ‘flex trees': a preliminary analysis}},
url = {https://www.tandfonline.com/doi/full/10.1080/03066150.2016.1140646},
volume = {43},
year = {2016}
}
@article{McKay2016,
abstract = {In the context of rising resource demand, agricultural crops such as sugarcane are being promoted for their multiple uses in different commodity markets and as alternatives to fossil fuel equivalents (i.e. as a source of biofuel, bioelectricity and bioplastic). These commodities are also produced on an increasingly flexible basis, as sugarcane mills respond to price signals and switch between different crop uses. This paper offers a preliminary exploration into the politics of this latest development in the capitalist industrialization of agriculture. It does so by focusing primarily on flexing in Brazil and highlighting the role of the state in both creating markets for non-food products that sugarcane mills can now switch between and managing the tensions that arise from this. These tensions have concerned consumer prices for fuel, control of distribution infrastructure and conditions of land conversion, each prompting political interventions by the state. The paper then suggests how this same process is taking place, albeit shaped by different contexts, in Southern Africa and Cambodia. It concludes with some key questions for further research: is flexing eroding the distinction between crop regimes? How do primary processors decide what their product mix will be? And on what basis do state actors support flexing between agricultural products and investments in so-called bio-refineries?},
annote = {Uses case studies in Brazil, Cambodia and Southern Africa, to show that crop flexing has been both enabled and later regulated by the state.},
author = {McKay, Ben and Sauer, S{\'{e}}rgio and Richardson, Ben and Herre, Roman},
doi = {10.1080/03066150.2014.992016},
isbn = {0306-6150, 1743-9361},
issn = {17439361},
journal = {Journal of Peasant Studies},
keywords = {Brazil,Cambodia,Southern Africa,ethanol,flex crops,sugarcane},
language = {en},
mendeley-groups = {Flex crops master thesis/Flex crops},
mendeley-tags = {flex crops},
number = {1},
pages = {195--223},
shorttitle = {The political economy of sugarcane flexing},
title = {{The political economy of sugarcane flexing: initial insights from Brazil, Southern Africa and Cambodia}},
url = {http://www.tandfonline.com/doi/full/10.1080/03066150.2014.992016},
volume = {43},
year = {2016}
}

Это код, который я использую

install.packages("remotes")
remotes::install_github("skgrange/threadr")
library(threadr)

bib <- read_bibtex(bib_file)
> bib$author
[1] "Kr\\\"oger, Markus"                                                  
[2] "McKay, Ben and Sauer, S\\'ergio and Richardson, Ben and Herre, Roman"

Как вы видите здесь, символ, который я здесь заканчиваю, это '\\ "o'. Пытаюсь это исправить:

bib_fixed = bib %>% 
  mutate_all(funs(str_replace(., '\\\"o', 'ö'))) %>% 
  mutate_all(funs(str_replace(., "\\'e", 'é')))
bib_fixed$author

> bib_fixed$author
[1] "Kr\\öger, Markus"                                                   
[2] "McKay, Ben and Sauer, S\\érgio and Richardson, Ben and Herre, Roman"

Но это не помогает, а только дает мне. Я ожидал, что первая запись будет «Крегер, Маркус», например.

Есть идеи, почему это не работает, или есть идеи, как решить эту проблему?

...