【问题标题】:Creating formatted references with different citation styles to academic papers without DOIs为没有 DOI 的学术论文创建具有不同引用风格的格式化参考文献
【发布时间】:2020-07-28 19:16:15
【问题描述】:

我想用 R 格式化对不同引用风格的学术论文的引用。

使用包 rcrossref,我可以轻松地根据某些文章的 DOI 以您指定的样式创建对某些文章的引用。然而,并不是所有的论文都有 DOI,所以我正在寻找一种简单的方法来根据来自 BibTeX 条目或其他类型输入的文章信息以不同样式的文本获取引文。

使用 rcrossref: 包内包含length(rcrossref::get_styles()) 2209种不同风格。

例如,您可以在列表元素的文本中以不同样式获取一些高被引论文(DOI 来自此来源:https://doi.org/10.1038/514550a)的文本引用,如下所示:

library(rcrossref)
# some DOIs of interest
dois <- c("10.1038/514550a", "10.1038/227680a0", "10.1016/0003-2697(76)90527-3",  "10.1073/Pnas.74.12.5463", "10.1016/0003-2697(87)90021-2", "10.1107/S0108767307043930")


# APA cv style
cr_cn(dois = dois, format = "text", style="apa-cv")
# same with Chicago style
cr_cn(dois = dois, format = "text", style="chicago-note-bibliography")
# same with Vancouver style
cr_cn(dois = dois, format = "text", style="vancouver")

现在,假设我有一个没有 DOI f.ex 的条目。 BibTex 格式,如:

@article {PMID:14907713,    Title = {Protein measurement with the Folin phenol reagent},    Author = {LOWRY, OH and ROSEBROUGH, NJ and FARR, AL and RANDALL, RJ},   Number = {1},   Volume = {193},     Month = {November},     Year = {1951},  Journal = {The Journal of biological chemistry},    ISSN = {0021-9258},     Pages = {265—275},  URL = {http://www.jbc.org/content/193/1/265.long} }  

我还想以 APA cv、Chicago 和 Vancouver 样式格式化此条目 f.ex,并以文本形式获得结果,我该怎么做?我还没有找到一个功能。目前有什么方法可以完成这项任务吗?

谢谢!

【问题讨论】:

    标签: r bibtex citations


    【解决方案1】:

    所以看起来rcrossref 不支持这一点,因为一切都发生在他们的 API 服务器上,而且似乎没有办法指定没有 DOI 的原始 bibtex 条目。

    但是,pandoc(通常与RStudio 一起安装并由rmarkdown 使用)似乎支持引用格式。我尝试做一些逆向工程,看看是否有可能只为给定条目生成引文。这是我创建的函数。

    citation <- function(bib, csl="chicago-author-date.csl", toformat="plain", cslrepo="https://raw.githubusercontent.com/citation-style-language/styles/master") {
      if (!file.exists(bib)) {
        message("Assuming input is literal bibtex entry")
        tmpbib <- tempfile(fileext = ".bib")
        on.exit(unlink(tmpbib), add=TRUE)
        if(!validUTF8(bib)) {
          bib <- iconv(bib, to="UTF-8")
        }
        writeLines(bib, tmpbib)
        bib <- tmpbib
      }
      if (tools::file_ext(csl)!="csl") {
        warning("CSL file name should end in '.csl'")
      }
      if (!file.exists(csl)) {
        cslurl <- file.path(cslrepo, csl)
        message(paste("Downling CSL from", cslurl))
        cslresp <- httr::GET(cslurl, httr::write_disk(csl))
        if(httr::http_error(cslresp)) {
          stop(paste("Could not download CSL.", "Code:", httr::status_code(cslresp)))
        }
      }
      tmpcit <- tempfile(fileext = ".md")
      on.exit(unlink(tmpcit), add=TRUE)
      
      writeLines(c("---","nocite: '@*'","---"), tmpcit)
      rmarkdown::find_pandoc()
      command <- paste(shQuote(rmarkdown:::pandoc()), 
                       "--filter", "pandoc-citeproc",
                       "--to", shQuote(toformat),
                       "--csl", shQuote(csl),
                       "--bibliography", shQuote(bib), 
                      shQuote(tmpcit))
      rmarkdown:::with_pandoc_safe_environment({
        result <- system(command, intern = TRUE)
        Encoding(result) <- "UTF-8"
      })
      result
    }
    

    您可以传入您的参考资料,它会使用标准的“CSL”文件对其进行转换。这些 CSL 文件控制格式。有一个针对不同格式的具有不同 CSL 的巨型存储库 here。您可以指定一个 CSL 文件,如果该文件不存在,此函数将自动从 repo 下载它。

    您可以传入“原始”引用

    test <- "@article {PMID:14907713,    Title = {Protein measurement with the Folin phenol reagent},    Author = {LOWRY, OH and ROSEBROUGH, NJ and FARR, AL and RANDALL, RJ},   Number = {1},   Volume = {193},     Month = {November},     Year = {1951},  Journal = {The Journal of biological chemistry},    ISSN = {0021-9258},     Pages = {265-275},  URL = {http://www.jbc.org/content/193/1/265.long} } "
    citation(test)
    

    或者如果数据在文件中,您可以使用文件名

    writeLines(test, "test.bib") 
    citation("test.bib")
    

    如果您想使用不同的 CSL,您只需在 CSL= 参数中设置 CSL 文件的名称

    citation("test.bib", csl="apa-cv.csl")
    citation("test.bib", csl="chicago-note-bibliography.csl")
    citation("test.bib", csl="vancouver.csl")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-25
      • 2021-08-18
      • 2018-08-28
      • 1970-01-01
      • 2014-09-29
      • 1970-01-01
      相关资源
      最近更新 更多