mirror of
https://github.com/freeCodeCamp/devdocs
synced 2024-11-16 19:48:10 +01:00
Add R documentation
Contains the R base + recommended package help pages converted to HTML. Equivalent to the fullrefman.pdf generated from source, which is also called « The R Reference Index » on https://cran.r-project.org/manuals.html Currently does not include reference manuals and miscellanea (FAQ, etc.) Script building the documentation: ```bash set -e set -o pipefail DEVDOCSROOT=/path/to/devdocs/docs/r RSOURCEDIR=${TMPDIR:-/tmp}/R/latest RBUILDDIR=${TMPDIR:-/tmp}/R/build RLATEST=https://cran.r-project.org/src/base/R-latest.tar.gz R="$RBUILDDIR/bin/R" libdir="$RBUILDDIR/library" docdir=$RBUILDDIR/doc makevars="$RSOURCEDIR/share/make/vars.mk" if [ ! -f "$R" ] ; then if [ ! -d "$RSOURCEDIR" ]; then mkdir -p "$RSOURCEDIR" && curl "$RLATEST" | tar -C "$RSOURCEDIR" -xzf - --strip-components=1 fi [ -d "$RBUILDDIR" ] || mkdir -p "$RBUILDDIR" [ -f "$RBUILDDIR/config.status" ] || (cd "$RBUILDDIR" && "$RSOURCEDIR/configure") make -C "$RBUILDDIR" && make -C "$RBUILDDIR" docs fi mkdir -p "$DEVDOCSROOT/doc" && cp -r "$docdir"/* "$DEVDOCSROOT/doc/" find "$libdir" -type d -name 'html' -printf '%P\n' | while read d; do mkdir -p "$DEVDOCSROOT/library/$d" cp -r "$libdir/$d"/* "$DEVDOCSROOT/library/$d/" done R_PKGS_BASE="`sed -n 's/^R_PKGS_BASE *= *//p' $makevars`" R_PKGS_RECOMMENDED="`sed -n 's/^R_PKGS_RECOMMENDED *= *//p' $makevars`" cat <<EOF | _R_HELP_LINKS_TO_TOPICS_=FALSE $R --vanilla --no-echo links <- tools::findHTMLlinks() for (pkg in c(`echo $R_PKGS_BASE $R_PKGS_RECOMMENDED | sed 's/\S\+/"&"/g;s/ /, /g'`)) { Rd <- tools::Rd_db(pkg, lib.loc="$libdir") if (!length(Rd)) { message(paste("ERROR: no help files found for package", pkg)) } else { message(paste0(pkg, "...")) } for(f in names(Rd)) { out <- file.path("$DEVDOCSROOT/library", pkg, "html", sub("[Rr]d$", "html", basename(f))) tools::Rd2HTML(Rd[[f]], out, package = "$pkg", defines = .Platform\$OS.type, outputEncoding = "UTF-8", no_links = FALSE, dynamic = FALSE, Links = links, stages = c("build", "install", "render")) } } EOF echo "DONE! Start at $DEVDOCSROOT/doc/html/index.html (or $DEVDOCSROOT/doc/html/packages.html)" ```
This commit is contained in:
parent
cce7c49152
commit
0b38f339f1
7 changed files with 130 additions and 0 deletions
|
@ -676,6 +676,11 @@ credits = [
|
|||
'2012-2018 The Qt Company Ltd',
|
||||
'GFDL',
|
||||
'https://doc.qt.io/qt-5/licensing.html'
|
||||
], [
|
||||
'R',
|
||||
'1999--2012 R Foundation for Statistical Computing',
|
||||
'GPL',
|
||||
'https://svn.r-project.org/R/trunk/COPYING'
|
||||
], [
|
||||
'Ramda',
|
||||
'2013-2020 Scott Sauyet and Michael Hurley',
|
||||
|
|
34
lib/docs/filters/r/clean_html.rb
Normal file
34
lib/docs/filters/r/clean_html.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
module Docs
|
||||
class R
|
||||
class CleanHtmlFilter < Filter
|
||||
def call
|
||||
slug_parts = slug.split('/')
|
||||
if slug_parts[0] == 'library'
|
||||
title = at_css('h2')
|
||||
title.inner_html = "<code>#{slug_parts[3]}</code> #{title.content}"
|
||||
|
||||
summary = at_css('table[summary]')
|
||||
summary.remove if summary
|
||||
|
||||
elsif slug_parts[-2] == 'manual'
|
||||
css('span[id] + h1, span[id] + h2, span[id] + h3, span[id] + h4, span[id] + h5, span[id] + h6').each do |node|
|
||||
id = node.previous['id']
|
||||
node.previous.remove
|
||||
node['id'] = id.sub(/-1$/, '') if id
|
||||
end
|
||||
css('table.menu, div.header, hr').remove
|
||||
|
||||
css('.footnote h5').each do |node|
|
||||
anchor = node.at_css('a[id]')
|
||||
footnote = node.next_sibling
|
||||
footnote.inner_html = "<strong>#{anchor.text}</strong> #{footnote.inner_html}"
|
||||
footnote['id'] = anchor['id']
|
||||
node.remove
|
||||
end
|
||||
end
|
||||
|
||||
doc
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
59
lib/docs/filters/r/entries.rb
Normal file
59
lib/docs/filters/r/entries.rb
Normal file
|
@ -0,0 +1,59 @@
|
|||
module Docs
|
||||
class R
|
||||
class EntriesFilter < Docs::EntriesFilter
|
||||
|
||||
@@include_manual = false
|
||||
@@include_misc = false
|
||||
|
||||
def initialize(*)
|
||||
super
|
||||
end
|
||||
|
||||
def slug_parts
|
||||
slug.split('/')
|
||||
end
|
||||
|
||||
def is_package?
|
||||
slug_parts[0] == 'library'
|
||||
end
|
||||
|
||||
def is_manual?
|
||||
slug_parts[-2] == 'manual'
|
||||
end
|
||||
|
||||
def get_name
|
||||
return slug_parts[3] + ' − ' + at_css('h2').content if is_package?
|
||||
title = at_css('h1.settitle')
|
||||
title ? title.content : at_css('h1, h2').content
|
||||
end
|
||||
|
||||
def get_type
|
||||
return slug_parts[1] if is_package?
|
||||
return at_css('h1.settitle').content if is_manual?
|
||||
'Miscellaneous'
|
||||
end
|
||||
|
||||
def include_default_entry?
|
||||
if is_manual? or slug_parts[-1] == '00Index' or slug_parts[-1] == 'index'
|
||||
return false
|
||||
end
|
||||
is_package? or self.include_misc
|
||||
end
|
||||
|
||||
def additional_entries
|
||||
return [] unless is_manual? and self.include_manual
|
||||
|
||||
entries = []
|
||||
css('div.contents > ul > li').each do |node|
|
||||
node.css('a').each do |link|
|
||||
link_name = link.content.sub /^[0-9A-Z]+(\.[0-9]+)* /, ''
|
||||
entries << [link_name, link['href'].split('#')[1], name]
|
||||
end
|
||||
end
|
||||
return entries
|
||||
end
|
||||
|
||||
private
|
||||
end
|
||||
end
|
||||
end
|
31
lib/docs/scrapers/r.rb
Normal file
31
lib/docs/scrapers/r.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
module Docs
|
||||
class R < FileScraper
|
||||
self.name = 'R'
|
||||
self.slug = 'r'
|
||||
self.type = 'simple'
|
||||
self.release = '4.1.0'
|
||||
self.links = {
|
||||
home: 'https://www.r-project.org/',
|
||||
code: 'https://svn.r-project.org/R/'
|
||||
}
|
||||
|
||||
self.root_path = 'doc/html/packages.html'
|
||||
|
||||
html_filters.push 'r/entries', 'r/clean_html'
|
||||
|
||||
options[:skip_links] = false
|
||||
|
||||
options[:attribution] = <<-HTML
|
||||
Copyright (©) 1999--2012 R Foundation for Statistical Computing.<br>
|
||||
Licensed under the <a href="https://www.gnu.org/copyleft/gpl.html">GNU General Public License</a>.
|
||||
HTML
|
||||
|
||||
# Never want those
|
||||
options[:skip] = %w(
|
||||
doc/html/packages-head-utf8.html
|
||||
doc/html/SearchOn.html
|
||||
doc/html/Search.html
|
||||
)
|
||||
|
||||
end
|
||||
end
|
BIN
public/icons/docs/r/16.png
Normal file
BIN
public/icons/docs/r/16.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 716 B |
BIN
public/icons/docs/r/16@2x.png
Normal file
BIN
public/icons/docs/r/16@2x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
1
public/icons/docs/r/SOURCE
Normal file
1
public/icons/docs/r/SOURCE
Normal file
|
@ -0,0 +1 @@
|
|||
https://svn.r-project.org/R/trunk/doc/html/Rlogo.svg
|
Loading…
Reference in a new issue