将Bibtex类对象转换为一系列针对每个引用格式化的文本字符串

问题描述

我是bibTex对象的新手,并希望为对象中的每个引用生成一个格式为格式的引用的文本字符串列表。我不想生成文档-这些字符串将用于R中的下游目的。有没有办法做到这一点?我什至无法真正弄清楚如何访问bibTex对象中的每个引用。

换一种说法,我该如何转:

   temp <- toBibtex(c(citation("base"),citation("sp")))

对此:

  [[1]]
  [1] "R Core Team (2019). R: A language and environment for statistical computing. R Foundation for Statistical Computing,Vienna,Austria. https://www.R-project.org/."

  [[2]]
  [1] "Pebesma,E.J.,R.S. Bivand (2005). Classes and methods for spatial data in R. R News 5. https://cran.r-project.org/doc/Rnews/."

  [[3]]
  [1] "Bivand,R.S.,Pebesma,Gomez-Rubio,V. (2013). Applied spatial data analysis with R,Second edition. Springer,NY. https://asdar-book.org/."

帮助?

解决方法

使用 bib2df 软件包:

library(bibtex)
library(bib2df)

write.bib(c("base","sp"),"temp.bib")

x <- bib2df("temp.bib")

apply(x,1,function(i){
  paste(
    #adding authors and titles
    paste(unlist(i$AUTHOR),collapse = ","),i$TITLE,# add other bits here as needed
    sep = ",")
})

# [1] "R Core Team,R: A Language and Environment for Statistical Computing"                                        
# [2] "Edzer J. Pebesma,Roger S. Bivand,Classes and methods for spatial data in {R"                               
# [3] "Roger S. Bivand,Edzer Pebesma,Virgilio Gomez-Rubio,Applied spatial data analysis with {R},Second edition"

注意:我也是bibtex的新手。还有 RefManageR 包,可能会更有用。


使用 RefManageR

library(RefManageR)

# read bib file
x1 <- ReadBib("temp.bib")
# or convert citations to bibentry object
x2 <- as.BibEntry(c(citation("base"),citation("sp")))

两者都将打印如下:

# [1] R. S. Bivand,E. Pebesma,and V. Gomez-Rubio. _Applied spatial data analysis with R,Second
# edition_. Springer,NY,2013. <URL: https://asdar-book.org/>.
# 
# [2] E. J. Pebesma and R. S. Bivand. “Classes and methods for spatial data in R”. In: _R News_ 5.2 (Nov.
#                                                                                                    2005),pp. 9-13. <URL: https://CRAN.R-project.org/doc/Rnews/>.
# [3] R Core Team. _R: A Language and Environment for Statistical Computing_. R Foundation for
# Statistical Computing. Vienna,Austria,2019. <URL: https://www.R-project.org/>.
,

我认为您可以应用类似以下代码的内容:

pkgs <- c("base","sp")
lapply(pkgs,function(x) citation(x)$textVersion)
#> [[1]]
#> [1] "R Core Team (2020). R: A language and environment for statistical computing. R Foundation for Statistical Computing,Vienna,Austria. URL https://www.R-project.org/."
#> 
#> [[2]]
#> [[2]][[1]]
#> [1] "Pebesma,E.J.,R.S. Bivand,2005. Classes and methods for spatial data in R. R News 5 (2),https://cran.r-project.org/doc/Rnews/."
#> 
#> [[2]][[2]]
#> [1] "Roger S. Bivand,2013. Applied spatial data analysis with R,Second edition. Springer,NY. https://asdar-book.org/"

或者,如果您需要为列表的每个元素恰好需要1个引用,那么我认为您可以运行:

as.list(unlist(lapply(pkgs,function(x) citation(x)$textVersion)))
#> [[1]]
#> [1] "R Core Team (2020). R: A language and environment for statistical computing. R Foundation for Statistical Computing,Austria. URL https://www.R-project.org/."
#> 
#> [[2]]
#> [1] "Pebesma,https://cran.r-project.org/doc/Rnews/."
#> 
#> [[3]]
#> [1] "Roger S. Bivand,NY. https://asdar-book.org/"

reprex package(v0.3.0)于2020-09-30创建

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...