Permalink
Browse files

whoops, include new files in push

  • Loading branch information...
cboettig committed Feb 1, 2013
1 parent aff8246 commit 821f1b7bf80a1c20d3774c6849b797490c11d7b7
View
@@ -3,7 +3,7 @@ Type: Package
Title: Citations for knitr markdown files
Authors@R: person("Carl", "Boettiger", role=c("aut", "cre"),
email="cboettig@gmail.com")
-Version: 0.3-0
+Version: 0.3-1
Date: 2012-03-24
Description: While traditional Sweave documents can take advantage of LaTeX
citation tools, knitr also allows users to combine the much simpler
@@ -18,6 +18,8 @@ Imports:
xtable,
RCurl,
XML
+Suggests:
+ testthat
License: CC0
Collate:
'functiontable.R'
View
@@ -2,18 +2,9 @@
#' @param style formatting style to print bibliography (default is HTML). Can be
#' text, bibtex, html, or other formats defined forthe print bibentry class,
#' see ?print.bibentry for details.
-#' @param erase logical indicating that bibliographic list generated
-#' during this session will be erased after the bibliography is printed,
-#' defaults to FALSE
#' @param sort logical indicating if bibliography should be sorted
#' alphabetically, defaults to FALSE
-#' @param addkeys logical indicating if a list of keys should be added
-#' to the citation list, in case keys are not yet present. Keys are
-#' automatically (or manually) added by the inline citet/citep functions,
-#' so this defaults to false.
-#' @param debug logical to turn on debug mode, which doesn't strip
-#' duplicates by key. Defaults to FALSE.
-#' @param use bibtex method (internal option only)
+#' @param bibtex logical, use bibtex data structure internally? (internal option only)
#' @return a list of bibentries, providing a bibliography of what's been cited
#' @details reads in the values from the option "works_cited",
#' possibly applying tidying up and formatting as well.
@@ -36,6 +27,9 @@ bibliography <- function(style="html", sort=FALSE, bibtex=getOption("bibtex_data
+
+####### Methods below are depricated ###########
+
#' A simple method to determine unique bibentries by bibkey
#'
#' Uses the bibkey ids to identify unique entries. see uniquebib
View
@@ -0,0 +1,14 @@
+#' Erase existing list of works cited
+#' @param bibtex logical, internal use parameter only.
+#'
+#' @details simply overwrites knitcitations.bib in bibtex data logging mode.
+#' (which means bibtex is used for internal data; not that the input data comes
+#' from bibtex. Input data can come from any source, bibtex or DOI, as shown
+#' in the documentation).
+#' @export
+newbib <- function(bibtex = getOption("bibtex_data")){
+ if(bibtex)
+ write("", file = "knitcitations.bib")
+ else
+ rm(list = ls(envir = knitcitationsCache), envir = knitcitationsCache)
+}
View
@@ -7,6 +7,7 @@
#' If FALSE (default), the file is overwritten.
#' @param verbose a logical to toggle verbosity. If 'file=NULL', verbosity is
#' forced off.
+#' @param create_key logical indicating whether function should create a bibtex citation key if the object doesn't have one.
#' @return a list of citation information, invisibly
#'
#' The 'knitcitations' package automatically extends the use of this function to
@@ -15,10 +16,8 @@
#'
#' @import bibtex
#' @examples
-#' write.bibtex(c('bibtex', 'knitr', 'knitcitations'), file="example.bib")
-#' refs <- lapply(c("10.1111/j.1461-0248.2005.00827.x","10.1890/11-0011.1"), ref)
-#' write.bibtex(refs, file="refs.bib")
-#'
+#' write.bibtex(c("Yihui2013" = citation("knitr"), "Boettiger2013" = citation("knitcitations"), "TempleLang2012"=citation("RCurl")))
+#' bib <- read.bibtex("knitcitations.bib")
#' @export
#' @seealso read.bib citep citet
write.bibtex <- function(entry, file="knitcitations.bib", append=FALSE, verbose=TRUE, create_key=TRUE){
View
@@ -0,0 +1,31 @@
+#' write knitcitations data to a cache object instead of a file
+#'
+#' @param a_bibentry a bibentry object, possibly already named with a key
+#' @param bibtex logical, use a bibtex file for the cache of cited works rather than an environment?
+#' @return writes the bibentry to the environment 'knitcitationsCache', created by
+write_cache <- function(a_bibentry, bibtex = getOption("bibtex_data")){
+ ## Create a bibkey for the entry if it doesn't have one.
+ if(is.null(names(a_bibentry))){
+ a_bibentry <- create_bibkey(a_bibentry)
+ }
+
+ if(bibtex)
+ write.bibtex(a_bibentry, "knitcitations.bib", append=TRUE)
+ else
+ assign(names(a_bibentry), a_bibentry, knitcitationsCache)
+}
+
+
+
+read_cache <- function(bibtex=getOption("bibtex_data")){
+ if(bibtex)
+ read.bibtex("knitcitations.bib")
+ else {
+ files <- ls(envir=knitcitationsCache)
+ out <- sapply(files, get, knitcitationsCache, USE.NAMES=FALSE)
+ class(out) = "bibentry"
+ out
+ }
+}
+
+
File renamed without changes.
View
@@ -0,0 +1,20 @@
+test_that("Citation handles all types", {
+ a <- citep("10.1890/11-0011.1")
+ expect_is(a, "AsIs")
+ expect_equivalent(a, I("(Abrams _et. al._ 2012)"))
+})
+
+
+
+test_that("knitcitations_data file initialized", {
+ a <- citep("10.1890/11-0011.1")
+ # create a bibentry object of this article
+ b <- ref("10.1890/11-0011.1")
+ # cite the bibentry object, should avoid creating a duplicate
+ a2 <- citep(b)
+ # Did this create a bibfile we can read?
+# b <- read.bib("knitcitations.bib")
+# expect_is(b, "bibentry")
+})
+
+# entry entered as doi, later as doi again, later as bibentry, later as bibkey. Does this avoid duplicates?
View
@@ -0,0 +1,4 @@
+Bilder2006 <- ref("10.3998/3336451.0009.101")
+test_that("DOI returned field values as expected", {
+ expect_equal(ref("10.3998/3336451.0009.101")$title, "in Google we Trust?")
+})
View
@@ -11,23 +11,11 @@
formats defined forthe print bibentry class, see
?print.bibentry for details.}
- \item{erase}{logical indicating that bibliographic list
- generated during this session will be erased after the
- bibliography is printed, defaults to FALSE}
-
\item{sort}{logical indicating if bibliography should be
sorted alphabetically, defaults to FALSE}
- \item{addkeys}{logical indicating if a list of keys
- should be added to the citation list, in case keys are
- not yet present. Keys are automatically (or manually)
- added by the inline citet/citep functions, so this
- defaults to false.}
-
- \item{debug}{logical to turn on debug mode, which doesn't
- strip duplicates by key. Defaults to FALSE.}
-
- \item{use}{bibtex method (internal option only)}
+ \item{bibtex}{logical, use bibtex data structure
+ internally? (internal option only)}
}
\value{
a list of bibentries, providing a bibliography of what's
@@ -4,6 +4,11 @@
\usage{
knitcitations_data(bibtex = getOption("bibtex_data"))
}
+\arguments{
+ \item{bibtex}{the option to use bibtex}
+
+ \item{the}{updated value of the option to use bibtex}
+}
\description{
Helper function to get knit data
}
View
@@ -0,0 +1,20 @@
+\name{newbib}
+\alias{newbib}
+\title{Erase existing list of works cited}
+\usage{
+ newbib(bibtex = getOption("bibtex_data"))
+}
+\arguments{
+ \item{bibtex}{logical, internal use parameter only.}
+}
+\description{
+ Erase existing list of works cited
+}
+\details{
+ simply overwrites knitcitations.bib in bibtex data
+ logging mode. (which means bibtex is used for internal
+ data; not that the input data comes from bibtex. Input
+ data can come from any source, bibtex or DOI, as shown in
+ the documentation).
+}
+
View
@@ -18,6 +18,10 @@
\item{verbose}{a logical to toggle verbosity. If
'file=NULL', verbosity is forced off.}
+
+ \item{create_key}{logical indicating whether function
+ should create a bibtex citation key if the object doesn't
+ have one.}
}
\value{
a list of citation information, invisibly
@@ -31,9 +35,8 @@
write a bibtex file
}
\examples{
-write.bibtex(c('bibtex', 'knitr', 'knitcitations'), file="example.bib")
- refs <- lapply(c("10.1111/j.1461-0248.2005.00827.x","10.1890/11-0011.1"), ref)
- write.bibtex(refs, file="refs.bib")
+write.bibtex(c("Yihui2013" = citation("knitr"), "Boettiger2013" = citation("knitcitations"), "TempleLang2012"=citation("RCurl")))
+ bib <- read.bibtex("knitcitations.bib")
}
\seealso{
read.bib citep citet
View
@@ -0,0 +1,23 @@
+\name{write_cache}
+\alias{write_cache}
+\title{write knitcitations data to a cache object instead of a file}
+\usage{
+ write_cache(a_bibentry,
+ bibtex = getOption("bibtex_data"))
+}
+\arguments{
+ \item{a_bibentry}{a bibentry object, possibly already
+ named with a key}
+
+ \item{bibtex}{logical, use a bibtex file for the cache of
+ cited works rather than an environment?}
+}
+\value{
+ writes the bibentry to the environment
+ 'knitcitationsCache', created by
+}
+\description{
+ write knitcitations data to a cache object instead of a
+ file
+}
+
View
@@ -0,0 +1,3 @@
+library(testthat)
+library(knitcitations)
+test_package("knitcitations")

0 comments on commit 821f1b7

Please sign in to comment.