r - 使用摘要从 R 编写 .bib 文件
问题描述
我有 .bib 文件(从 web of science 下载),我想将其导入 R,用“CONSIDERING”替换“in light of”的所有实例,并将其导出为 .bib 文件。我一直无法找到可以将我的数据写回 .bib 文件的函数。WriteBib 不起作用,因为 refs 是“pairlist”对象,而不是“bibentry”。关于如何导出可以导入 Mendeley 的 .bib 文件的任何建议?感谢您的帮助!
这是代码:
library(bibtex)
library(RefManageR)
refs = do_read_bib("/Users/CarrieAnn/Downloads/savedrecs (1).bib", encoding = "unknown", srcfile)
for (i in 1:length(refs)) {
refs[[i]] = gsub("in light of", "CONSIDERING", refs[[i]])
}
解决方案
我认为您最简单的选择是将 .bib 文件视为普通文本文件。尝试这个:
raw_text <- readLines("example.bib")
new_text <- gsub("in light of", "CONSIDERING", raw_text)
writeLines(new_text, con="new_example.bib")
内容example.bib
:
% a sample bibliography file
%
@article{small,
author = {Doe, John},
title = {A small paper},
journal = {The journal of small papers},
year = 1997,
volume = {-1},
note = {in light of recent events},
}
@article{big,
author = {Smith, Jane},
title = {A big paper},
journal = {The journal of big papers},
year = 7991,
volume = {MCMXCVII},
note = {in light of what happened},
}
输出new_example.bib
:
% a sample bibliography file
%
@article{small,
author = {Doe, John},
title = {A small paper},
journal = {The journal of small papers},
year = 1997,
volume = {-1},
note = {CONSIDERING recent events},
}
@article{big,
author = {Smith, Jane},
title = {A big paper},
journal = {The journal of big papers},
year = 7991,
volume = {MCMXCVII},
note = {CONSIDERING what happened},
}
一点解释:
BibEntry
对象具有非标准的内部结构,并且在RefManageR
包中提供的功能之外很难使用。一旦你unclass
或将一个对象简化为一个列表,由于对象所需的字段和属性的混合,BibEntry
就很难将其放回格式。bib
(更糟糕的是,bibtex
内部RefManageR
结构并不完全相同,因此很难从一种上下文转换到另一种上下文。)
推荐阅读
- node.js - 在节点 js 中出现错误 - NODE_MODULE_VERSION
- eclipse - Mac 上的 Eclipse 终端不显示我输入的内容
- forms - 带有表单的 v-for 循环未分配值
- kubernetes - 加密配置映射中的秘密
- python-3.x - 使用 pyad 创建新的组织单位
- julia - 朱莉娅:具有列出功能的“使用”模块未定义模块本身
- javascript - 页面的设置阻止了内联资源的加载(“script-src”)
- python - 有没有办法在打开文件对话框中读取文件的详细信息/元数据?
- tomcat - Tomcat 服务器正在运行,但我无法再访问它
- c++ - unordered_set 中的哈希函数结果和桶号