Skip to content

Commit

Permalink
Merge pull request #158 from natverse/fix/fields-with-brackets
Browse files Browse the repository at this point in the history
Fix fields with brackets
  • Loading branch information
jefferis authored May 21, 2022
2 parents 95c6d31 + 244b5bf commit 6393b33
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ importFrom(dplyr,select)
importFrom(dplyr,ungroup)
importFrom(drvid,read.neuron.dvid)
importFrom(glue,glue)
importFrom(glue,glue_collapse)
importFrom(httr,parse_url)
importFrom(magrittr,"%>%")
importFrom(memoise,memoise)
Expand Down
9 changes: 7 additions & 2 deletions R/fetch.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,14 @@ neuprint_error_check <- function(req) {
#' @param stringsAsFactors Whether to return character vector columns as
#' factors. Note that the default of \code{FALSE} differs from
#' \code{\link{data.frame}} and friends.
#' @param check.names Whether to convert column names into R friendly form. This
#' is not necessary but would be the default for \code{\link{data.frame}} were
#' we not to set it ourselves. See \code{\link{as.data.frame}} for details.
#' @param ... Additional arguments passed to \code{\link{as.data.frame}}
#'
#' @export
neuprint_list2df <- function(x, cols=NULL, return_empty_df=FALSE,
check.names=FALSE,
stringsAsFactors=FALSE, ...) {

if(length(x)>=2 && all(c("columns", "data") %in% names(x))) {
Expand All @@ -87,7 +92,7 @@ neuprint_list2df <- function(x, cols=NULL, return_empty_df=FALSE,

if(!length(x)) {
return(if(return_empty_df){
as.data.frame(structure(replicate(length(cols), logical(0)), .Names=cols))
as.data.frame(structure(replicate(length(cols), logical(0)), .Names=cols), check.names=check.names)
} else NULL)
}

Expand All @@ -108,7 +113,7 @@ neuprint_list2df <- function(x, cols=NULL, return_empty_df=FALSE,
}
l[[cols[i]]]=raw_col
}
as.data.frame(l, stringsAsFactors=stringsAsFactors, ...)
as.data.frame(l, stringsAsFactors=stringsAsFactors, check.names=check.names, ...)
}

#' @importFrom memoise memoise
Expand Down
7 changes: 5 additions & 2 deletions R/name.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ neuprint_get_neuron_names <- function(bodyids, dataset = NULL, all_segments = TR
#' \dontrun{
#' neuprint_get_meta('cropped:false')
#' }
#' @importFrom glue glue_collapse glue
neuprint_get_meta <- function(bodyids, dataset = NULL, all_segments = TRUE,
conn = NULL, chunk=TRUE, progress=FALSE,
possibleFields=NULL, ...){
Expand Down Expand Up @@ -147,7 +148,9 @@ neuprint_get_meta <- function(bodyids, dataset = NULL, all_segments = TRUE,
fieldNames <- neuprint_get_fields(possibleFields = possibleFields,
dataset=dataset,conn=conn)
rfields=dfFields(fieldNames)
returnCypher <- paste0("n.",fieldNames," AS ",rfields,collapse=" , ")
returnCypher <- glue("n.`{dfields}` AS `{rfields}`",
dfields=fieldNames)
returnCypher=glue_collapse(returnCypher, sep = ',')
cypher = glue(
"WITH {id2json(bodyids)} AS bodyIds UNWIND bodyIds AS bodyId ",
" MATCH (n:`{node}`) WHERE n.bodyId=bodyId",
Expand Down Expand Up @@ -485,7 +488,7 @@ neuprint_typeof <- function(field, type=c("r", "neo4j"), cache=TRUE,
q <- if(type=='r') {"
MATCH (n:Neuron)
WHERE exists(n.`{field}`)
RETURN n.{field} AS {field}
RETURN n.`{field}` AS `{field}`
LIMIT 1
" } else {"
MATCH (n:Neuron)
Expand Down
5 changes: 5 additions & 0 deletions man/neuprint_list2df.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6393b33

Please sign in to comment.