Difference between revisions of "Template:R"
Jump to navigation
Jump to search
m |
m |
||
(8 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | <code>[http:// | + | <noinclude> |
+ | Template to link R commands and packages to their respective information sources. | ||
+ | |||
+ | If the first parameter does not end in (), it is assumed to be a package. | ||
+ | Otherwise, it is assumed to be a function in base R. | ||
+ | |||
+ | If the second parameter is empty, the package link on rdocumentation.org is created. | ||
+ | Otherwise the function link is created. | ||
+ | |||
+ | If a third parameter is present, that will be the linked text. | ||
+ | |||
+ | Test cases: | ||
+ | {{R|mean()}} | ||
+ | {{R|knitr}} | ||
+ | {{R|graphics|par()}} | ||
+ | {{R|grDevices|colorRamp()|colorRampPalette()}} | ||
+ | |||
+ | <code> | ||
+ | {{#if: {{#pos: {{{1|}}} |() }} | ||
+ | #yes: it's a base function. construct link. | ||
+ | | | ||
+ | [http://www.rdocumentation.org/packages/base/functions/{{#replace:{{{1}}}|()|}} | ||
+ | #if second or third parameter is present, that will be the linked text. | ||
+ | {{#if: {{{2|}}}|{{{2}}}| | ||
+ | {{#if: {{{3|}}}|{{{3}}}| | ||
+ | {{{1}}} | ||
+ | }} | ||
+ | }} | ||
+ | ] | ||
+ | |||
+ | |||
+ | #no: it's a package. construct link | ||
+ | | | ||
+ | [http://www.rdocumentation.org/packages/{{{1}}}/functions/ | ||
+ | |||
+ | # if a second parameter is present, that is the function we want | ||
+ | {{#if: {{{2|}}} | ||
+ | |{{#replace:{{{2}}}|()|}} | ||
+ | |||
+ | # else, construct the link to the package doc. | ||
+ | |{{{1}}}-package | ||
+ | |||
+ | }} | ||
+ | |||
+ | # if a third parameter is present, that is the linked text | ||
+ | {{#if: {{{3|}}} | ||
+ | | {{{3}}} | ||
+ | |||
+ | # else, the linked text is {{{2}}} if present, {{{1}}} if not | ||
+ | | | ||
+ | {{#if: {{{2|}}}| {{{2}}}| {{{1}}} }} | ||
+ | |||
+ | }} | ||
+ | ] | ||
+ | }} | ||
+ | </code> | ||
+ | |||
+ | |||
+ | </noinclude><code>{{#if:{{#pos:{{{1|}}}|()}}|[http://www.rdocumentation.org/packages/base/functions/{{#replace:{{{1}}}|()|}} {{#if: {{{2|}}}|{{{2}}}|{{#if: {{{3|}}}|{{{3}}}|{{{1}}}}}}}]|[http://www.rdocumentation.org/packages/{{{1}}}/functions/{{#if:{{{2|}}}|{{#replace:{{{2}}}|()|}}|{{{1}}}-package}} {{#if:{{{3|}}}|{{{3}}}|{{#if:{{{2|}}}|{{{2}}}|{{{1}}}}}}}]}}</code> |
Latest revision as of 18:16, 16 January 2015
Template to link R commands and packages to their respective information sources.
If the first parameter does not end in (), it is assumed to be a package. Otherwise, it is assumed to be a function in base R.
If the second parameter is empty, the package link on rdocumentation.org is created. Otherwise the function link is created.
If a third parameter is present, that will be the linked text.
Test cases:
mean()
knitr
par()
colorRampPalette()
[http://www.rdocumentation.org/packages/base/functions/{{{1}}}
- if second or third parameter is present, that will be the linked text.
{{{1}}}
]
- no: it's a package. construct link