From edd at debian.org  Fri Jun  9 13:34:58 2017
From: edd at debian.org (Dirk Eddelbuettel)
Date: Fri, 9 Jun 2017 06:34:58 -0500
Subject: [Rd] Creating a private CRAN with webpages
In-Reply-To: <CAKShX4DwkwUcxfx32V1FiOzTnGCUrki5YQ2fxLFqtwU0o6zCaA@mail.gmail.com>
References: <CAKShX4CtPHh=KjAksnYtv7zaBX3-9Qrzv-Jw0udx4njWmvPC2g@mail.gmail.com>
 <CED2E38E-2C4C-452F-AFCF-46416C1836EC@icloud.com>
 <CAKShX4DwkwUcxfx32V1FiOzTnGCUrki5YQ2fxLFqtwU0o6zCaA@mail.gmail.com>
Message-ID: <22842.34786.743789.364253@max.eddelbuettel.com>


On 9 June 2017 at 02:44, Joshua Bradley wrote:
| repo. I like the CRAN web pages that allow a user to browse the various
| packages from a browser without having to first install them. I want to
| duplicate the process that CRAN goes through when it generate the webpages.

As your initial email correctly identified, none of miniCRAN, drat, ... do
this currently.

So this is how open source works: you identified a need, now you can go off
and fill it. ;-) You have the PACKAGES{,.gz,.rds} files from your repo. So
accessing packageDescription() for each package is a given.  I do so in
CRANberries for new packages, and while that (ugly) code is (still) not
public, the relevant function for that is

writeNewBlogEntry <- function(curPkg, curVer, reposurl) {
    ## and compute some sort of output for new package -- maybe get description ? NB does NOT work for BioC
    blogpost <- file.path(blogInputDir, "new", paste(curPkg, "_", curVer, ".txt", sep=""))
    con <- file(blogpost, "wt")
    cat("New package", curPkg, "with initial version", curVer,"\n\n", file=con)
    dcf <- read.dcf( url(getDescriptionUrl(curPkg, reposurl)) )
    for (i in 1:ncol(dcf)) {
        cat("<strong>", colnames(dcf)[i], "</strong>: ", htmlEscape(dcf[1,i]), "<br>\n", sep="", file=con)
    }
    closeBlogPost(con, reposurl, curPkg)
}

(The read.dcf() off the package URL is no longer needed with CRAN_package_db().)

A corresponding file for the most recent 'new' package:

-----------------------------------------------------------------------------
New package Risk with initial version 1.0 

<strong>Package</strong>: Risk<br>
<strong>Type</strong>: Package<br>
<strong>Title</strong>: Computes 26 Financial Risk Measures for Any Continuous
Distribution<br>
<strong>Version</strong>: 1.0<br>
<strong>Date</strong>: 2017-06-05<br>
<strong>Author</strong>: Saralees Nadarajah, Stephen Chan<br>
<strong>Maintainer</strong>: Saralees Nadarajah &lt;mbbsssn2 at manchester.ac.uk&gt;<br>
<strong>Depends</strong>: R (&gt;= 3.0.1)<br>
<strong>Description</strong>: Computes 26 financial risk measures for any continuous distribution.  The 26 financial risk measures  include value at risk, expected shortfall due to Artzner et al. (1999) &lt;DOI:10.1007/s10957-011-9968-2&gt;, tail conditional median due to Kou et al. (2013) &lt;DOI:10.1287/moor.1120.0577&gt;, expectiles due to Newey and Powell (1987) &lt;DOI:10.2307/1911031&gt;, beyond value at risk due to Longin (2001) &lt;DOI:10.3905/jod.2001.319161&gt;, expected proportional shortfall due to Belzunce et al. (2012) &lt;DOI:10.1016/j.insmatheco.2012.05.003&gt;, elementary risk measure due to Ahmadi-Javid (2012) &lt;DOI:10.1007/s10957-011-9968-2&gt;, omega due to Shadwick and Keating (2002), sortino ratio due to Rollinger and Hoffman (2013), kappa  due to Kaplan and Knowles  (2004), Wang (1998)'s &lt;DOI:10.1080/10920277.1998.10595708&gt; risk measures, Stone (1973)'s &lt;DOI:10.2307/2978638&gt; risk measures, Luce (1980)'s &lt;DOI:10.1007/BF00135033&gt; risk measures, Sarin (1987)'s &lt;DOI:10.1007/BF00126387&gt; risk measures, Bronshtein and Kurelenkova (2009)'s risk measures.<br>
<strong>License</strong>: GPL (&gt;= 2)<br>
<strong>Packaged</strong>: 2017-06-08 13:57:28 UTC; mbbsssn2<br>
<strong>NeedsCompilation</strong>: no<br>
<strong>Repository</strong>: CRAN<br>
<strong>Date/Publication</strong>: 2017-06-08 15:19:54 UTC<br>

<p>
<a href="https://cran.r-project.org/package=Risk">More information about Risk at CRAN</a>
-----------------------------------------------------------------------------

If I did it today, I'd start with markdown, but you get the idea.  The page
is the (current) top of http://dirk.eddelbuettel.com/cranberries/cran/new/

I write these as minimal html (as I wrote that code ~ 10 years ago in the
pre-pandoc days) which then get fed into the blog engine.  That helps keeping
content and presentation (css, ...) separate.

I think you have everything you need in the PACKAGES.rds which you get back
as a (large) data.frame from tools::CRAN_package_db().

Hope this helps,  Dirk



-- 
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org


[Rd] Creating a private CRAN with webpages
Dirk Eddelbuettel