Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow neuprint_login to update connections #154

Merged
merged 4 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions R/conn.R
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@
#' # specify a default dataset (only required when >1 dataset available)
#' conn2=neuprint_login(server="https://server2.org",
#' token=Sys.getenv('NPSERVER2'), dataset="hemibrain")
#'
#' # make a connection to the same server but using a different dataset
#' # this may be more convenient than specifying the dataset argument
#' conn3=neuprint_login(conn2, dataset="vnc")
#' }
#' @export
#' @rdname neuprint_login
Expand Down Expand Up @@ -242,19 +246,27 @@ neuprint_login <- function(conn = NULL, Cache = TRUE, Force = FALSE, ...){
stop("To connect to : ", conn, ", you must name the server argument i.e.\n",
sprintf(" neuprint_login(server=\"%s\")", conn))
}
dots=pairlist(...)
# local function to update/check the dataset of the returned connection
check_dataset_nl <- function(conn) {
if(length(dots)==0 || is.null(dots$dataset)) return(conn)
conn$dataset=check_dataset(conn = conn, dataset = dots$dataset)
conn
}
if (is.null(conn)) {
if (!length(pairlist(...))) {
if (length(dots)==0) {
conn = neuprint_last_connection()
}
if (is.null(conn))
conn = neuprint_connection(...)
}
} else if(!is.null(dots$dataset))
conn$dataset=dots$dataset
if (!Force) {
if (!is.null(conn$authresponse))
return(invisible(conn))
return(invisible(check_dataset_nl(conn)))
cached_conn = neuprint_cached_connection(conn)
if (!is.null(cached_conn))
return(invisible(cached_conn))
return(invisible(check_dataset_nl(cached_conn)))
}
if(is.null(conn$server))
stop("Sorry you must specify a neuprint server! See ?neuprint_login for details!")
Expand Down
7 changes: 4 additions & 3 deletions R/name.R
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,10 @@ neuprint_search <- function(search, field = "name", fixed=FALSE, exact=NULL,
search <- regexres[,3]
}

if(field=="name"){
if(!isTRUE(field=="where")){
conn = neuprint_login(conn)
field = neuprint_name_field(conn)
if(field=="name")
field = neuprint_name_field(conn, dataset = dataset)
}
# we want fixed searches to be partial by default
if(isTRUE(fixed) && is.null(exact))
Expand All @@ -327,7 +328,7 @@ neuprint_search <- function(search, field = "name", fixed=FALSE, exact=NULL,
# this is a raw CYPHER query
where=search
} else {
fieldtype=neuprint_typeof(field, type = 'neo4j')
fieldtype=neuprint_typeof(field, type = 'neo4j', conn=conn, dataset = dataset)
if(fieldtype=="STRING") {
search=glue('\\"{search}\\"')
operator=ifelse(fixed, ifelse(exact, "=", "CONTAINS"), "=~")
Expand Down
4 changes: 4 additions & 0 deletions man/neuprint_login.Rd

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

8 changes: 6 additions & 2 deletions tests/testthat/test-conn.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ test_that("neuprint_login works", {
})

test_that("neuprint_connection works", {
skip("don't test bad connection specs")
# skip("don't test bad connection specs")
skip_if_offline()
expect_warning(expect_is(
neuprint_login(server = "neuprint.janelia.org",
conn <- neuprint_login(server = "neuprint.janelia.org",
dataset = 'hemibrain:v1.0.1',
Cache = F, Force = T),
"neuprint_connection"
),
regexp = "https://neuprint.janelia.org")

expect_s3_class(conn2 <- neuprint_login(conn, dataset="hemibrain:v1.1", Cache = F),
"neuprint_connection")
})