Mercurial > repos > mingchen0919 > tripal_db_explorer
diff search_contents.Rmd @ 6:4bc7752bfd72 draft
resources summary + search
| author | mingchen0919 |
|---|---|
| date | Mon, 19 Mar 2018 16:29:51 -0400 |
| parents | 5accedb3133e |
| children |
line wrap: on
line diff
--- a/search_contents.Rmd Mon Mar 19 00:43:50 2018 -0400 +++ b/search_contents.Rmd Mon Mar 19 16:29:51 2018 -0400 @@ -1,30 +1,57 @@ --- -title: 'HTML report title' +title: 'Tripal database explorer: search results' output: html_document: - number_sections: true - toc: true theme: cosmo highlight: tango - code_folding: hide --- ```{r setup, include=FALSE, warning=FALSE, message=FALSE} knitr::opts_chunk$set( - echo = TRUE, + echo = FALSE, error = TRUE ) ``` -# Code for computational analysis - -```{r 'step 1'} - -``` - -```{r 'ste[ 2'} - +```{r} +# get member ids after implementing search filtering +content_type_url = opt$X_u +path = "organism,genus=Fagus&name=ABall;contains" +path = sub('\\|', '&', opt$X_s) +search_url = paste0(content_type_url, '?', path) +search_members = fromJSON(search_url) +# search_url_rebuild = paste0(search_url, '&limit=', search_members$totalItems) +total_records = as.integer(opt$X_l) +if (total_records == 0) { + total_records = search_members$totalItems +} +search_url_rebuild = paste0(search_url, '&limit=', total_records) +re_search_members = fromJSON(search_url_rebuild) ``` +```{r} +# get requested field values from search results +request_paths = sub(',', '\\.', strsplit(opt$X_e, '\\|')[[1]]) +res = data.frame() +for (id in re_search_members$member$`@id`) { + member = as.data.frame(fromJSON(id)) + res = rbind(res, member[, request_paths]) +} +colnames(res) = request_paths +``` + +```{r} +if (nrow(res) < 1) { + cat('No records found.') +} else { + DT::datatable(res) +} +``` + +```{r} +# save results to file +write.table(res, file = opt$X_r, quote = FALSE, col.names = FALSE) +``` +
