Loading...
 

Profile_r_test13_parse_body

Unfinished work. Alfa state.


Playground with survey/questionnaire data collected through tracker forms, and displayed as survey results. You can apply the profile "Voting System" just after the R_demo profile has been applied, so that the tracker for Voting has id 2, and you will have the tracker created for you to have this example working with minimum extra clicks (until this test13 profile page is properly implemented). The fields numbered (so far only hardcoded here) as f_9, f_10 and f_11, are a few fields from the voting, that hold choices of people for a few positions in the association that does run the theoretical voting process.

Fetch data using TrackerList to fetch data (parse body param needed)

[+]

Display dummy data using a Barplot (parse body param needed)

[+]

Fetch data using ajax services and display using sjPlot

(parse body param is NOT needed in this case, since data is fetched form custom url via web services). You need to grant anonymous perms to export tracker data from that specific tracker.

{RR(bg="yellow" parse_body="n" echodebug=1)}
r <- getOption("repos")
r%22CRAN%22 <- "http://ftp.heanet.ie/mirrors/cran.r-project.org/"
options(repos=r)
install.packages("sjPlot")
install.packages("sjmisc")
install.packages("qdap")
install.packages("stringr")

      1. EXAMPLE with pre-set data frame by hand
marca<-c("opel","renault","renault")
model<-c("corsa","laguna","modus")
cilindrada<-c(1.2,1.9,1.5)
color<-c("blanc","vermell","violeta")
cotxes<-data.frame(marca,model,cilindrada,color)
cotxes

      1. FETCH tracker data using Ajax services
Use some url such as:


  1. If your tiki is not under localhost, adapt the path below for my.file
my.file <- "http://localhost/tiki-ajax_services.php?controller=tracker&action=export_items&trackerId=2&encoding=UTF-8&separator=%2C&delimitorL=%22&delimitorR=%22&CR=%25%25%25&listfields[]=9&listfields[]=10&listfields[]=11&recordsMax=-1"
my.df <- read.csv(my.file)
  1. colnames(my.df) <- c("f_9", "f_10", "f_11")
  2. unlist(str_split(colnames(my.df), "\\."))1
  3. str_split(colnames(my.df), "\\.")[[1]]1 # field name from f_9 in this example
  4. str_split(colnames(my.df), "\\.")[[2]]1 # field name from f_10 in this example
  5. str_split(colnames(my.df), "\\.")[[3]]1 # field name from f_11 in this example


  1. load libraries
library(sjPlot)
library(sjmisc)
  1. init default theme for plots
sjp.setTheme(geom.label.size = 2.5, axis.title.size = .9, axis.textsize = .9)
sjp.frq(cotxes$marca)
sjp.frq(my.df1) # this fails for unknown reason
str(my.df)
library(stringr)
my.df <- set_val_labels(my.df, c(str_split(colnames(my.df), "\\.")[[1]]1,
str_split(colnames(my.df), "\\.")[[2]]1,
str_split(colnames(my.df), "\\.")[[3]]1))
  1. summary(my.df)

  1. Get counts from the my.df for the sjp.frq function

  1. Maybe using rpivotTable ?

  1. Package rpivotTable
  2. Make Pivot Tables (as in desktop Office software) using R
  3. See: http://www.magesblog.com/2015/03/pivot-tables-with-r.html
    1. Install package
library(devtools)
install_github("ramnathv/htmlwidgets")
install_github("smartinsightsfromdata/rpivotTable")
    1. Load rpivotTable
library(rpivotTable)
data(mtcars)
    1. One line to create pivot table
rpivotTable(mtcars, rows="gear", col="cyl", aggregatorName="Average",
vals="mpg", rendererName="Treemap")

  1. Using Package qdap: NÒPE
  2. qdap:
  3. "Quantitative Discourse Analysis Package: Bridging the Gap Between Qualitative Data and Quantitative Analysis"
  4. library(qdap)
  5. counts()

{RR}

See: