Re: [Rd] R package BibTex entries: looking for a more general solution

2011-12-19 Thread Michael Friendly

On 12/19/2011 2:02 AM, Renaud Gaujoux wrote:

Hi,

I actually adapted and integrated this feature into Achim's -- nice -- 
function (posted on r-help).
Romain included it a couple of weeks ago into the bibtex package as 
function write.bib, and submitted the update to CRAN, but some NOTEs 
in the check delayed its availability on CRAN.

You can still install and try out the new version with:
install.packages(bibtex, repos=http://R-Forge.R-project.org;)

Keys for multiple citations are generated as pkgname%i, which 
might not be ideal, but works ok though. It might be better not number 
the first (main) citation. Romain, I think I will submit a patch for 
this.

Hope this helps.


Thanks, Renaud

I now have a working function, Rpackages.bib() that is roughly 
equivalent to your write.bib() and other related

material at
http://euclid.psych.yorku.ca/SCS/Private/Rbibs/

Also, see the document
http://euclid.psych.yorku.ca/SCS/Private/Rbibs/Rpkg-test.pdf
which reports some problems  perl fixes for the generated bibentries.  
These might be incorporated into
the functions to make the resulting bibtex files directly usable.  Your 
bibtex package seems the most natural place for

this.

Also, write.bib() doesn't seem to work unless you pass a list of package 
names.


 write.bib()
Error in is(entry, bibentry) :
  argument entry is missing, with no default
 write.bib(NULL)
Error in write.bib(NULL) :
  Invalid argument `entry`: expected a bibentry object or a character 
vector of package names.




best,
-Michael



--
Michael Friendly Email: friendly AT yorku DOT ca
Professor, Psychology Dept.
York University  Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele StreetWeb:   http://www.datavis.ca
Toronto, ONT  M3J 1P3 CANADA

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] R package BibTex entries: looking for a more general solution

2011-12-19 Thread Renaud Gaujoux

Indeed I broke the function when adding support for bibentry objects...
By the way, let's give credits back to Ceasars: I am not the author of 
the bibtex package, Romain Francois is. I just contributed the write.bib 
function, mainly inspired by Achim's function.


Romain, I will send a fix for this now.

Renaud

--
Renaud Gaujoux
Computational Biology - University of Cape Town
South Africa


On 19/12/2011 15:56, Michael Friendly wrote:

On 12/19/2011 2:02 AM, Renaud Gaujoux wrote:

Hi,

I actually adapted and integrated this feature into Achim's -- nice 
-- function (posted on r-help).
Romain included it a couple of weeks ago into the bibtex package as 
function write.bib, and submitted the update to CRAN, but some NOTEs 
in the check delayed its availability on CRAN.

You can still install and try out the new version with:
install.packages(bibtex, repos=http://R-Forge.R-project.org;)

Keys for multiple citations are generated as pkgname%i, which 
might not be ideal, but works ok though. It might be better not 
number the first (main) citation. Romain, I think I will submit a 
patch for this.

Hope this helps.


Thanks, Renaud

I now have a working function, Rpackages.bib() that is roughly 
equivalent to your write.bib() and other related

material at
http://euclid.psych.yorku.ca/SCS/Private/Rbibs/

Also, see the document
http://euclid.psych.yorku.ca/SCS/Private/Rbibs/Rpkg-test.pdf
which reports some problems  perl fixes for the generated 
bibentries.  These might be incorporated into
the functions to make the resulting bibtex files directly usable.  
Your bibtex package seems the most natural place for

this.

Also, write.bib() doesn't seem to work unless you pass a list of 
package names.


 write.bib()
Error in is(entry, bibentry) :
  argument entry is missing, with no default
 write.bib(NULL)
Error in write.bib(NULL) :
  Invalid argument `entry`: expected a bibentry object or a character 
vector of package names.




best,
-Michael





__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] R package BibTex entries: looking for a more general solution

2011-12-18 Thread Renaud Gaujoux

Hi,

I actually adapted and integrated this feature into Achim's -- nice -- 
function (posted on r-help).
Romain included it a couple of weeks ago into the bibtex package as 
function write.bib, and submitted the update to CRAN, but some NOTEs in 
the check delayed its availability on CRAN.

You can still install and try out the new version with:
install.packages(bibtex, repos=http://R-Forge.R-project.org;)

Keys for multiple citations are generated as pkgname%i, which might 
not be ideal, but works ok though. It might be better not number the 
first (main) citation. Romain, I think I will submit a patch for this.

Hope this helps.

Renaud

--
Renaud Gaujoux
Computational Biology - University of Cape Town
South Africa

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] R package BibTex entries: looking for a more general solution

2011-12-16 Thread Michael Friendly
Back in 2010 I raised this issue, and there was some discussion,

https://stat.ethz.ch/pipermail/r-devel/2010-November/058987.html

The goal, then, as now is to have a way to produce a bibtex-clean .bib 
file (i.e., not requiring
manual editing except in unusual circumstances) reflecting installed 
packages
for use in writing where one often needs/wants to cite all packages used 
in a given article.

Achim wrote the function below  which largely does this job, quite 
nicely now that most
DESCRIPTION files now contain Authors@R fields.  However, something 
changed since
R 2.11.1 when I tried this last, so that the function no longer 
generates keys for packages
which contain *more than one citation*.

I've tried debugging with browser(), but can't figure out how to make 
the lines around FIXME
work.  Can someone help?

You can see the result from this at
http://euclid.psych.yorku.ca/SCS/Private/Rbibs/Rpackages-2.14.0.bib
The function is also at:

# Original code by Achim Zeileis, 16 Dec 2009, R-help
# Added: support header and preamble

Rpackages.bib - function(filename = paste(Rpackages-,getRversion(), 
.bib, sep=),
 header=TRUE, preamble=NULL, suppress.warnings=TRUE, verbose = TRUE)
{
   ## installed packages
   pkgs - unique(installed.packages()[,1])
   if (suppress.warnings) warn - options(warn=-1)
   bibs - lapply(pkgs, function(x) try(toBibtex(citation(x
   if (suppress.warnings) options(warn)

   n.installed - length(bibs)

   ## omit failed citation calls
   ok - !(sapply(bibs, class) == try-error)
   pkgs - pkgs[ok]
   bibs - bibs[ok]
   n.converted - sum(ok)
   ## unify to list of Bibtex
   bibs - lapply(bibs, function(x) if(inherits(x, Bibtex)) list(x) 
else x)

   ## FIXME: add bibtex keys to each entry [the line below does not work!!]
   pkgs - lapply(seq_along(pkgs), function(i) if(length(bibs[[i]])  1)
 paste(pkgs[i], 1:length(bibs[[i]]), sep = ) else pkgs[i])
   pkgs - do.call(c, pkgs)
   bibs - do.call(c, bibs)
   for(i in seq_along(pkgs)) bibs[[i]][1] -
 gsub({,, paste({, pkgs[i], ,, sep = ), bibs[[i]][1], fixed 
= TRUE)

 if(header) header - gsub(^, %, toLatex(sessionInfo()))
 output - file(filename, a)
 cat(header, preamble, sep='\n', file=output, append=TRUE)
   ## write everything to a single .bib file
   writeLines(do.call(c, lapply(bibs, as.character)), con=output)
   close(output)
   if(verbose) cat(Converted, n.converted, of, n.installed,
 package citations to BibTeX,
 \nResults written to file, filename, \n)

   ## return Bibtex items invisibly
   invisible(bibs)
}






-- 
Michael Friendly Email: friendly AT yorku DOT ca
Professor, Psychology Dept.
York University  Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele StreetWeb:   http://www.datavis.ca
Toronto, ONT  M3J 1P3 CANADA


[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] R package BibTex entries: looking for a more general solution

2011-12-16 Thread Achim Zeileis

Michael,

meanwhile the bibentry class that Kurt mentioned back in the discussion 
in 2010 is fully implemented in R. Hence the code can be simplified when 
working with the bibentry objects directly (instead of the Bibtex 
objects derived from them).


I've quickly hacked some code to illustrate how the function needs to be 
modified but I didn't have the time to integrate it into the function

(I'm currently traveling).

  ## query packages and their bibentries
  pkgs - unique(installed.packages()[,1])
  bibs - lapply(pkgs, function(x) try(citation(x)))

  ## exclude those with errors
  ok - !(sapply(bibs, class) == try-error)
  pkgs - pkgs[ok]
  bibs - bibs[ok]

  ## number of bibentries per package
  nref - sapply(bibs, length)

  ## merge all bibentries
  bibs - do.call(c, bibs)

  ## add citation keys
  bibkeys - lapply(1:length(nref), function(i)
if(nref[i]  1) paste(pkgs[i], 1:nref[i], sep = :) else pkgs[i])
  bibs$key - as.list(unlist(bibkeys))

And then you just need to say toBibtex(bibs) or writeLines(toBibtex(bibs)) 
or something along those lines.


For more details on the new classes, see this recent working paper by Kurt 
Duncan and myself: http://epub.wu.ac.at/3269/.


So much for today.
Best wishes,
Z

On Fri, 16 Dec 2011, Michael Friendly wrote:


Back in 2010 I raised this issue, and there was some discussion,

https://stat.ethz.ch/pipermail/r-devel/2010-November/058987.html

The goal, then, as now is to have a way to produce a bibtex-clean .bib file
(i.e., not requiring
manual editing except in unusual circumstances) reflecting installed
packages
for use in writing where one often needs/wants to cite all packages used in
a given article.

Achim wrote the function below  which largely does this job, quite nicely
now that most
DESCRIPTION files now contain Authors@R fields.  However, something changed
since
R 2.11.1 when I tried this last, so that the function no longer generates
keys for packages
which contain more than one citation.

I've tried debugging with browser(), but can't figure out how to make the
lines around FIXME
work.  Can someone help?

You can see the result from this at
http://euclid.psych.yorku.ca/SCS/Private/Rbibs/Rpackages-2.14.0.bib
The function is also at:

# Original code by Achim Zeileis, 16 Dec 2009, R-help
# Added: support header and preamble

Rpackages.bib - function(filename = paste(Rpackages-,getRversion(),
.bib, sep=),
        header=TRUE, preamble=NULL, suppress.warnings=TRUE, verbose = TRUE)
{
  ## installed packages
  pkgs - unique(installed.packages()[,1])
  if (suppress.warnings) warn - options(warn=-1)
  bibs - lapply(pkgs, function(x) try(toBibtex(citation(x
  if (suppress.warnings) options(warn)
 
  n.installed - length(bibs)

  ## omit failed citation calls
  ok - !(sapply(bibs, class) == try-error)
  pkgs - pkgs[ok]
  bibs - bibs[ok]
  n.converted - sum(ok)
  ## unify to list of Bibtex
  bibs - lapply(bibs, function(x) if(inherits(x, Bibtex)) list(x) else x)

  ## FIXME: add bibtex keys to each entry [the line below does not work!!]
  pkgs - lapply(seq_along(pkgs), function(i) if(length(bibs[[i]])  1)
    paste(pkgs[i], 1:length(bibs[[i]]), sep = ) else pkgs[i])
  pkgs - do.call(c, pkgs)
  bibs - do.call(c, bibs)
  for(i in seq_along(pkgs)) bibs[[i]][1] -
    gsub({,, paste({, pkgs[i], ,, sep = ), bibs[[i]][1], fixed =
TRUE)

    if(header) header - gsub(^, %, toLatex(sessionInfo()))
    output - file(filename, a)
    cat(header, preamble, sep='\n', file=output, append=TRUE)
  ## write everything to a single .bib file
  writeLines(do.call(c, lapply(bibs, as.character)), con=output)
  close(output)
  if(verbose) cat(Converted, n.converted, of, n.installed,
    package citations to BibTeX,
    \nResults written to file, filename, \n)

  ## return Bibtex items invisibly
  invisible(bibs)
}






--
Michael Friendly Email: friendly AT yorku DOT ca 
Professor, Psychology Dept.

York University  Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele StreetWeb:   http://www.datavis.ca
Toronto, ONT  M3J 1P3 CANADA

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] R package BibTex entries: looking for a more general solution

2010-11-03 Thread Yihui Xie
I strongly support this proposal! I also find it inconvenient to cite
some R packages and really do not like edit the BibTeX entries
manually.

Regards,
Yihui
--
Yihui Xie xieyi...@gmail.com
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA



On Wed, Nov 3, 2010 at 8:44 AM, Michael Friendly frien...@yorku.ca wrote:
 == Summary ==
 * Problem: BibTeX entries extracted from R packages via citation() require
 too much manual editing to be
 of general use.
 * Proposal: Date: fields should be made mandatory in package DESCRIPTION
 files, perhaps
 beginning with warnings from R CMD check
 * Proposal: Package authors should be encouraged to use a (new)
 Contributors: field in the DESCRIPTION file
 rather than packing all information into the Author: field, which at present
 cannot often be parsed by BibTeX.
 * Files: All test files referred to here can be found at

 http://euclid.psych.yorku.ca/SCS/Private/Rbibs/

 == Details ==
 Around 16 Dec. 2009, I queried R-help about automating the extraction of
 citation()s from R packages. The stimulus
 was that some journals, notably JSS, now require a reference and citation of
 every R package mentioned,
 and it is a pain to create these manually, no less maintain them for current
 versions.

 The result of that query was a function, Rpackage.bibs() by Achim Zeileis
 that I have been using ever since.
 Code in: http://euclid.psych.yorku.ca/SCS/Private/Rbibs/Rpackages.bib.R
 On one current system I get the following:

 Rpackage.bibs(file=Rpackages-R.2.11.1.bib)
 Converted 230 of 230 package citations to BibTex
 Results written to file Rpackages-R.2.11.1.bib
 Warning messages:
 1: In citation(x) :
 no date field in DESCRIPTION file of package 'codetools'
 2: In citation(x) :
 no date field in DESCRIPTION file of package 'gridBase'
 3: In citation(x) : no date field in DESCRIPTION file of package 'iplots'

 See:
 http://euclid.psych.yorku.ca/SCS/Private/Rbibs/Rpkg-test.pdf
 for the result of processing this .bib file with latex/bibtex using the
 jss.bst bibliography style

 I'm writing to R-Devel because the DESCRIPTION and inst/CITATION files in R
 packages provide the
 basic data used in citation() and any methods based on this, and yet the
 information in these files is
 often insufficient to generate well-formed BibTeX entries for use in
 vignettes and publications.

 One easy case is illustrated above, where 3 packages have no Date: field so
 the BibTeX gets no
 year = {},
 and references get printed as Murrell, P () for gridBase. (In my
 original test under R 2.9.1, there where
 ~ 20 such warnings.) Thus, I propose that Date: be a required field in
 DESCRIPTION files, and
 R CMD check complain if this is not found.

 The more difficult case has to do with the Author: field in the DESCRIPTION
 file (when no CITATION file is present)
 People can write whatever they want here, and the result looks sort of OK
 when printed by citation(), but confuses
 BibTeX mightly. One example:

 citation(akima)
 To cite package ‘akima’ in publications use:

 Fortran code by H. Akima R port by Albrecht Gebhardt aspline function
 by Thomas Petzoldt petzo...@rcs.urz.tu-dresden.de enhancements and
 corrections by Martin Maechler (2009). akima: Interpolation of
 irregularly spaced data. R package version 0.5-4.
 http://CRAN.R-project.org/package=akima

 A BibTeX entry for LaTeX users is

 @Manual{,
 title = {akima: Interpolation of irregularly spaced data},
 author = {Fortran code by H. Akima R port by Albrecht Gebhardt aspline
 function by Thomas Petzoldt petzo...@rcs.urz.tu-dresden.de enhancements
 and corrections by Martin Maechler},
 year = {2009},
 note = {R package version 0.5-4},
 url = {http://CRAN.R-project.org/package=akima},
 }

 ATTENTION: This citation information has been auto-generated from the
 package DESCRIPTION file and may need manual editing, see
 ‘help(citation)’ .


 Yes, the ATTENTION note does say that manual editing may be necessary, but I
 think a worthy goal would be
 to try to reduce the need for this.

 One simple way to do that would be to support an extra Contributions: field
 in the DESCRIPTION file,
 so that Authors: can be more cleanly separated for the purpose of creating
 well-structured BibTeX.
 Perhaps others have better ideas.

 -Michael

 --
 Michael Friendly     Email: friendly AT yorku DOT ca
 Professor, Psychology Dept.
 York University      Voice: 416 736-5115 x66249 Fax: 416 736-5814
 4700 Keele Street    Web:http://www.datavis.ca
 Toronto, ONT  M3J 1P3 CANADA

 __
 R-devel@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel


__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] R package BibTex entries: looking for a more general solution

2010-11-03 Thread Kurt Hornik
 Michael Friendly writes:

Thanks for the suggestions. In fact, we are currently working on this
issue. A lot of improvements have already been done, see ?person and
?bibentry for R 2.12.0 or later, especially the details and examples
sections. Some more work still needs to be done, though. We will write a
primer that introduces the new features when all of them are available.

Best
-k

 == Summary ==
 * Problem: BibTeX entries extracted from R packages via citation() 
 require too much manual editing to be
 of general use.
 * Proposal: Date: fields should be made mandatory in package DESCRIPTION 
 files, perhaps
 beginning with warnings from R CMD check
 * Proposal: Package authors should be encouraged to use a (new) 
 Contributors: field in the DESCRIPTION file
 rather than packing all information into the Author: field, which at 
 present cannot often be parsed by BibTeX.
 * Files: All test files referred to here can be found at

 http://euclid.psych.yorku.ca/SCS/Private/Rbibs/

 == Details ==
 Around 16 Dec. 2009, I queried R-help about automating the extraction of 
 citation()s from R packages. The stimulus
 was that some journals, notably JSS, now require a reference and 
 citation of every R package mentioned,
 and it is a pain to create these manually, no less maintain them for 
 current versions.

 The result of that query was a function, Rpackage.bibs() by Achim 
 Zeileis that I have been using ever since.
 Code in: http://euclid.psych.yorku.ca/SCS/Private/Rbibs/Rpackages.bib.R
 On one current system I get the following:

 Rpackage.bibs(file=Rpackages-R.2.11.1.bib)
 Converted 230 of 230 package citations to BibTex
 Results written to file Rpackages-R.2.11.1.bib
 Warning messages:
 1: In citation(x) :
 no date field in DESCRIPTION file of package 'codetools'
 2: In citation(x) :
 no date field in DESCRIPTION file of package 'gridBase'
 3: In citation(x) : no date field in DESCRIPTION file of package 'iplots'
 
 See:
 http://euclid.psych.yorku.ca/SCS/Private/Rbibs/Rpkg-test.pdf
 for the result of processing this .bib file with latex/bibtex using the 
 jss.bst bibliography style

 I'm writing to R-Devel because the DESCRIPTION and inst/CITATION files 
 in R packages provide the
 basic data used in citation() and any methods based on this, and yet the 
 information in these files is
 often insufficient to generate well-formed BibTeX entries for use in 
 vignettes and publications.

 One easy case is illustrated above, where 3 packages have no Date: field 
 so the BibTeX gets no
 year = {},
 and references get printed as Murrell, P () for gridBase. (In my 
 original test under R 2.9.1, there where
 ~ 20 such warnings.) Thus, I propose that Date: be a required field in 
 DESCRIPTION files, and
 R CMD check complain if this is not found.

 The more difficult case has to do with the Author: field in the 
 DESCRIPTION file (when no CITATION file is present)
 People can write whatever they want here, and the result looks sort of 
 OK when printed by citation(), but confuses
 BibTeX mightly. One example:

 citation(akima)
 To cite package ‘akima’ in publications use:

 Fortran code by H. Akima R port by Albrecht Gebhardt aspline function
 by Thomas Petzoldt petzo...@rcs.urz.tu-dresden.de enhancements and
 corrections by Martin Maechler (2009). akima: Interpolation of
 irregularly spaced data. R package version 0.5-4.
 http://CRAN.R-project.org/package=akima

 A BibTeX entry for LaTeX users is

 @Manual{,
 title = {akima: Interpolation of irregularly spaced data},
 author = {Fortran code by H. Akima R port by Albrecht Gebhardt aspline 
 function by Thomas Petzoldt petzo...@rcs.urz.tu-dresden.de 
 enhancements and corrections by Martin Maechler},
 year = {2009},
 note = {R package version 0.5-4},
 url = {http://CRAN.R-project.org/package=akima},
 }

 ATTENTION: This citation information has been auto-generated from the
 package DESCRIPTION file and may need manual editing, see
 ‘help(citation)’ .
 

 Yes, the ATTENTION note does say that manual editing may be necessary, 
 but I think a worthy goal would be
 to try to reduce the need for this.

 One simple way to do that would be to support an extra Contributions: 
 field in the DESCRIPTION file,
 so that Authors: can be more cleanly separated for the purpose of 
 creating well-structured BibTeX.
 Perhaps others have better ideas.

 -Michael

 -- 
 Michael Friendly Email: friendly AT yorku DOT ca
 Professor, Psychology Dept.
 York University  Voice: 416 736-5115 x66249 Fax: 416 736-5814
 4700 Keele StreetWeb:http://www.datavis.ca
 Toronto, ONT  M3J 1P3 CANADA

 __
 R-devel@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel