diff --git a/NAMESPACE b/NAMESPACE index b6a1d5ea..2d69a87c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/R/fetch.R b/R/fetch.R index b7acb5ae..e1604d59 100644 --- a/R/fetch.R +++ b/R/fetch.R @@ -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))) { @@ -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) } @@ -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 diff --git a/R/name.R b/R/name.R index da8df877..2441cfff 100644 --- a/R/name.R +++ b/R/name.R @@ -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, ...){ @@ -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", @@ -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) diff --git a/man/neuprint_list2df.Rd b/man/neuprint_list2df.Rd index 6384ce4d..ac0cb81b 100644 --- a/man/neuprint_list2df.Rd +++ b/man/neuprint_list2df.Rd @@ -8,6 +8,7 @@ neuprint_list2df( x, cols = NULL, return_empty_df = FALSE, + check.names = FALSE, stringsAsFactors = FALSE, ... ) @@ -20,6 +21,10 @@ all of those named in \code{x}, see details).} \item{return_empty_df}{Return a zero row data frame when there is no result.} +\item{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.} + \item{stringsAsFactors}{Whether to return character vector columns as factors. Note that the default of \code{FALSE} differs from \code{\link{data.frame}} and friends.}