File: Rsource.xml

package info (click to toggle)
r-cran-xml 3.99-0.18-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 3,688 kB
  • sloc: ansic: 6,656; xml: 2,890; asm: 486; sh: 12; makefile: 2
file content (47 lines) | stat: -rw-r--r-- 1,120 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?xml version="1.0"?>

<article xmlns:r='http://www.r-project.org'>

<para>
This is a very simple example of using an XML file to create annotated
R code that defines some functions and also has a "main" script
in the style of Python scripts that can be loaded or run.

<r:function id="myFun">
myFun = 
function(n)
{
  sum(sample(1:10, n, replace = TRUE))
}
</r:function>
</para>

<para>
We define a second function
and we use an id attribute "B"
eventhough this is not the name of the function.
Note also that we use the CDATA construct
to specify the content of the node as 
the code contains characters &lt; and &gt;
and &amp; that are special to XML.
<r:function id="B">
<![CDATA[
inRect <-
function(pos, x, y, w, h)
{
  pos[1] >= x & pos[2] >= y &   pos[1] <= x + w & pos[2] <= y + h
}
]]>
</r:function>
We only need to surround this code with the start and end of the CDATA
delimeters and we don't have to escape the individual characters.
This makes it easier to cut and paste the code directly into another
application.
</para>
<para>
<r:code>
inRect(c(10, 10), 3, 4, 10, 10)
myFun()
</r:code>
</para>
</article>