|
5
|
1 ---
|
|
6
|
2 title: 'Tripal database explorer: search results'
|
|
5
|
3 output:
|
|
|
4 html_document:
|
|
|
5 theme: cosmo
|
|
|
6 highlight: tango
|
|
|
7 ---
|
|
|
8
|
|
|
9 ```{r setup, include=FALSE, warning=FALSE, message=FALSE}
|
|
|
10 knitr::opts_chunk$set(
|
|
6
|
11 echo = FALSE,
|
|
5
|
12 error = TRUE
|
|
|
13 )
|
|
|
14 ```
|
|
|
15
|
|
|
16
|
|
6
|
17 ```{r}
|
|
|
18 # get member ids after implementing search filtering
|
|
|
19 content_type_url = opt$X_u
|
|
|
20 path = "organism,genus=Fagus&name=ABall;contains"
|
|
|
21 path = sub('\\|', '&', opt$X_s)
|
|
|
22 search_url = paste0(content_type_url, '?', path)
|
|
|
23 search_members = fromJSON(search_url)
|
|
|
24 # search_url_rebuild = paste0(search_url, '&limit=', search_members$totalItems)
|
|
|
25 total_records = as.integer(opt$X_l)
|
|
|
26 if (total_records == 0) {
|
|
|
27 total_records = search_members$totalItems
|
|
|
28 }
|
|
|
29 search_url_rebuild = paste0(search_url, '&limit=', total_records)
|
|
|
30 re_search_members = fromJSON(search_url_rebuild)
|
|
5
|
31 ```
|
|
|
32
|
|
|
33
|
|
6
|
34 ```{r}
|
|
|
35 # get requested field values from search results
|
|
|
36 request_paths = sub(',', '\\.', strsplit(opt$X_e, '\\|')[[1]])
|
|
|
37 res = data.frame()
|
|
|
38 for (id in re_search_members$member$`@id`) {
|
|
|
39 member = as.data.frame(fromJSON(id))
|
|
|
40 res = rbind(res, member[, request_paths])
|
|
|
41 }
|
|
|
42 colnames(res) = request_paths
|
|
|
43 ```
|
|
|
44
|
|
|
45 ```{r}
|
|
|
46 if (nrow(res) < 1) {
|
|
|
47 cat('No records found.')
|
|
|
48 } else {
|
|
|
49 DT::datatable(res)
|
|
|
50 }
|
|
|
51 ```
|
|
|
52
|
|
|
53 ```{r}
|
|
|
54 # save results to file
|
|
|
55 write.table(res, file = opt$X_r, quote = FALSE, col.names = FALSE)
|
|
|
56 ```
|
|
|
57
|