Loading...
 
Skip to main content

History: Profile_r_test1_simple_test

Source of version: 9

Copy to clipboard
            Simple R commands to test that the installation went fine

!!# Text output
This code:
{CODE()}
{R()}1:10{R}
{CODE}

Produces:
{R()}1:10{R}

!!# Simple Graphical output
This code:
{CODE()}
{R()}plot(1:10,11:20){R}
{CODE}

Produces:
{R()}plot(1:10,11:20){R}

!!# Basic image with svg and pdf export
This code:
{CODE()}
{R(svg="1", pdf="1")}x<-c(1:10)
y <- x*x
plot(x,y)
{R}
{CODE}

Produces:
{R(svg="1", pdf="1")}x<-c(1:10)
y <- x*x
plot(x,y)
{R}

!! Calling commands with admin validation (like install.packages, etc)
This command will attempt to install an R package, and it will require from an admin validation before it can be run from Tiki to the R server behind:
{CODE(colors="r",wrap="1")}
{RR(loadandsave="1", wikisyntax="0", removen="0")}
#   Example adapted from the ones shown here:  http://code.google.com/p/google-motion-charts-with-r/  
#   and here: http://www.r-bloggers.com/interactive-reports-in-r-with-knitr-and-rstudio/
#
# If required the first time, uncomment the following line/s to install the required R packages, and edit the path and url to suite your needs
if(!require(googleVis)){
	install.packages("googleVis", repos="http://ftp.heanet.ie/mirrors/cran.r-project.org/")
}
{RR}
{CODE}

Will produce:
{RR(loadandsave="1", wikisyntax="0", removen="0")}
# Example adapted from the ones shown here:  http://code.google.com/p/google-motion-charts-with-r/  
#   and here: http://www.r-bloggers.com/interactive-reports-in-r-with-knitr-and-rstudio/
#
# If required the first time, uncomment the following line/s to install the required R packages, and edit the path and url to suite your needs
if(!require(googleVis)){
	install.packages("googleVis", repos="http://ftp.heanet.ie/mirrors/cran.r-project.org/")
}
{RR}

Once validated, it will show something like this (the fist time when the package was not installed yet):
{QUOTE()}
	'googleVis.Rnw' 

The downloaded source packages are in
	'/tmp/RtmpbI9rP4/downloaded_packages'
{QUOTE}

Or if we do't want to show the warning messages of the package loading on the wiki page, we can call the loading of the library with: -+suppressPackageStartupMessages(library(googleVis))+-

Therefore, this:
{CODE()}
{RR(loadandsave="1", wikisyntax="0")}
suppressPackageStartupMessages(library(googleVis))
{RR}
{CODE}

Will produce this other output:
^
{RR(loadandsave="1", wikisyntax="0")}
suppressPackageStartupMessages(library(googleVis))
{RR}
(nothing)
^

!!# Graphical output with advanced packages
Using GoogleVis package, for instance.

!!!# Basic chart with information shown when mousing over the points
This code:
{CODE(colors="r",wrap="1")}
{R(wikisyntax="0" loadandsave="1", removen="0")}
require(googleVis)
df <- data.frame(x = 1:10, y = 1:10)

## load the googleVis package
suppressPackageStartupMessages(library(googleVis))
## create the scatter chart
sc <- gvisScatterChart(data=df,
                        options=list(width=300, height=300, 
                                     legend='none',
                                     hAxis="{title:'x'}",
                                     vAxis="{title:'y'}")

          )

##
print(sc, "chart")  ## same as cat(sc$html$chart)
{R}
{CODE}

Produces:

{R(wikisyntax="0" loadandsave="1" type="text/csv" onefile="0", removen="0")}
require(googleVis)
df <- data.frame(x = 1:10, y = 1:10)
## load the googleVis package
suppressPackageStartupMessages(library(googleVis))
## create the scatter chart
sc <- gvisScatterChart(data=df,
                        options=list(width=300, height=300, 
                                     legend='none',
                                     hAxis="{title:'x'}",
                                     vAxis="{title:'y'}")
          )
print(sc, "chart")  ## same as cat(sc$html$chart)
{R}

!!!# Basic Geolocated Map
This code:
{CODE(colors="r",wrap="1")}
{R(loadandsave="1", wikisyntax="0", removen="0")}
require(googleVis)
geo <- gvisGeoChart(CityPopularity, locationvar = "City",
                    colorvar = "Popularity", 
          options = list(region="US", height=350, displayMode = "markers",
                         colorAxis = "{colors: ['orange','blue']}") )
print(geo, "chart")
{R}
{CODE}

Produces:

{R(loadandsave="1", wikisyntax="0", removen="0")}
require(googleVis)
geo <- gvisGeoChart(CityPopularity, locationvar = "City",
                    colorvar = "Popularity", 
          options = list(region="US", height=350, displayMode = "markers",
                         colorAxis = "{colors: ['orange','blue']}") )
print(geo, "chart")
{R}

!!! Animated flash charts with time series data
This code:
{CODE(colors="r",wrap="1")}
{R(loadandsave="1", wikisyntax="0", removen="0")}
require(googleVis)
M <- gvisMotionChart(Fruits, "Fruit", "Year", options = list(width = 550, 
    height = 450))
print(M, "chart")
{R}
{CODE}

Produces:

{R(loadandsave="1", wikisyntax="0", removen="0")}
require(googleVis)
M <- gvisMotionChart(Fruits, "Fruit", "Year", options = list(width = 550, 
    height = 450))
print(M, "chart")
{R}


And once everything is ready in your system (all packages installed, etc), you'll see something like this:

{img src="http://ueb.vhir.org/display577"  styleimage="border" }

        

History

Information Version
Sat 31 of Aug, 2013 08:03 GMT-0000 Xavier de Pedro updated 11
Thu 30 of May, 2013 10:41 GMT-0000 Xavier de Pedro adedd echo param 10
Sun 24 of Mar, 2013 23:42 GMT-0000 Xavier de Pedro updated and simplified the first test 9
Sun 06 of Jun, 2010 16:28 GMT-0000 Xavier de Pedro 8
Sun 06 of Jun, 2010 16:14 GMT-0000 Xavier de Pedro 7
Fri 04 of Jun, 2010 18:05 GMT-0000 Xavier de Pedro 6
Wed 02 of Jun, 2010 09:39 GMT-0000 Xavier de Pedro 5
Mon 22 of Feb, 2010 20:52 GMT-0000 Xavier de Pedro 4
Mon 22 of Feb, 2010 19:35 GMT-0000 Xavier de Pedro 3
Mon 22 of Feb, 2010 19:27 GMT-0000 Xavier de Pedro 2
Sun 21 of Feb, 2010 13:44 GMT-0000 Xavier de Pedro initial version after replacing "Bug tracker" with "R_test" and "bug" with "dataset" 1