Convert a Bibtex class object to a series of text strings formatted for each citation

Hannah O.

I'm new to bibTex objects, and want to generate a list of text strings for each citation in the object as a formatted citation. I don't want to generate a document--these strings will be used for a downstream purpose within R. Is there a way to do this? I can't even really figure out how to access the pieces of each citation in a bibTex object.

Put another way, how to I turn this:

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

into this:

  [[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, E.J., Gomez-Rubio, V. (2013). Applied spatial data analysis with R, Second edition. Springer, NY. https://asdar-book.org/."

Help?

zx8754

Using bib2df package:

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"

Note: I am new to bibtex, too. There is also RefManageR package, might be more useful.


Using RefManageR:

library(RefManageR)

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

Both will print as below:

# [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/>.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Convert range formatted as date to text

분류에서Dev

Convert formatted email (HTML) to plain Text?

분류에서Dev

python pandas dataframe to csv exporting a formatted text file with unique formats for each column

분류에서Dev

Html display formatted text

분류에서Dev

Convert formatted cstring number to long

분류에서Dev

Type mismatch: cannot convert from Object to Class object

분류에서Dev

Is it safe to concatenate formatted strings using sprintf()?

분류에서Dev

Find a block of text in formatted text file

분류에서Dev

How to convert list of IDs formatted in varchar into int

분류에서Dev

calling function with dataframe data gives error (cannot convert the series to <class 'float'>)

분류에서Dev

Convert pandas series into integers

분류에서Dev

Showing XAML formatted text in WPF TextBlock

분류에서Dev

Deserializing weirdly formatted JSON to an object in C#

분류에서Dev

Update a JSON formatted JavaScript object based on another

분류에서Dev

Adding vertical line to Date formatted time-series in matplotlib

분류에서Dev

Convert an array of strings in the view Web Form View Engine format to javaScript Object

분류에서Dev

Convert list of strings to dictionary

분류에서Dev

Comparing strings of text files

분류에서Dev

PHP convert time, day,month and year to a formatted string

분류에서Dev

How do I convert a Json file (that contains a array) to a List (of a class object) C# Unity

분류에서Dev

To chop of the last string from a series of strings separated by "/"

분류에서Dev

Regex parsing issues of multi-line entries containing formatted text

분류에서Dev

Changing values in pre-formatted text using javascript

분류에서Dev

Javascript on .each class getval

분류에서Dev

Convert cell array to array of strings

분류에서Dev

Extracting Specific Strings From Text

분류에서Dev

Calling underscore each (_.each) on an object's method

분류에서Dev

Class object not detected as class in Java

분류에서Dev

How to distinguish each class in intent?

Related 관련 기사

  1. 1

    Convert range formatted as date to text

  2. 2

    Convert formatted email (HTML) to plain Text?

  3. 3

    python pandas dataframe to csv exporting a formatted text file with unique formats for each column

  4. 4

    Html display formatted text

  5. 5

    Convert formatted cstring number to long

  6. 6

    Type mismatch: cannot convert from Object to Class object

  7. 7

    Is it safe to concatenate formatted strings using sprintf()?

  8. 8

    Find a block of text in formatted text file

  9. 9

    How to convert list of IDs formatted in varchar into int

  10. 10

    calling function with dataframe data gives error (cannot convert the series to <class 'float'>)

  11. 11

    Convert pandas series into integers

  12. 12

    Showing XAML formatted text in WPF TextBlock

  13. 13

    Deserializing weirdly formatted JSON to an object in C#

  14. 14

    Update a JSON formatted JavaScript object based on another

  15. 15

    Adding vertical line to Date formatted time-series in matplotlib

  16. 16

    Convert an array of strings in the view Web Form View Engine format to javaScript Object

  17. 17

    Convert list of strings to dictionary

  18. 18

    Comparing strings of text files

  19. 19

    PHP convert time, day,month and year to a formatted string

  20. 20

    How do I convert a Json file (that contains a array) to a List (of a class object) C# Unity

  21. 21

    To chop of the last string from a series of strings separated by "/"

  22. 22

    Regex parsing issues of multi-line entries containing formatted text

  23. 23

    Changing values in pre-formatted text using javascript

  24. 24

    Javascript on .each class getval

  25. 25

    Convert cell array to array of strings

  26. 26

    Extracting Specific Strings From Text

  27. 27

    Calling underscore each (_.each) on an object's method

  28. 28

    Class object not detected as class in Java

  29. 29

    How to distinguish each class in intent?

뜨겁다태그

보관