R/addins.R

Defines functions NewProject StartPatchmasteR get_exampledata example_

NewProject <- function() {
    require(ephys2)
    require(shiny)
    require(shinyTree)
    options(shiny.launch.browser = .rs.invokeShinyPaneViewer)
    rm(tree, envir = .GlobalEnv)
    StartPatchmasteR()
}

StartPatchmasteR <- function() {
  require(ephys2)
  require(shiny)
  require(shinyTree)
  options(shiny.launch.browser = .rs.invokeShinyPaneViewer)
    if (!exists("tree")) {
        
        tempDir <- tempfile()
        dir.create(tempDir)
        htmlFile <- file.path(tempDir, "test.html")
        writeLines("<html><body><H1>Please choose a file!</H1><p>File dialoue might be hidden behind this window</p></body></html>", 
            htmlFile)
        viewer <- getOption("viewer")
        viewer(htmlFile)
        files <- choose.files(".\\*.dat")
        htmlFile2 <- file.path(tempDir, "test2.html")
        writeLines("<html><body></body></html>", htmlFile2)
        viewer(htmlFile2)
        
        if (length(files) == 0) {
            return("no file chosen")
        }
        
        files = files[1]  #we have to fix this, but reorder_tree does not work with pmfiles yet
        tree <- reorder_tree(get_treeinfo(files), 1:8)
        names(tree) <- files
    }
    print(getwd())
    load(file = "CURSORS", .GlobalEnv)
    tree <<- showtree(tree)
    save(CURSORS, file = "CURSORS", .GlobalEnv)
}



#' Copy example files to the current directory
#'
#' you will get an example .dat file and Anadef plus render functions.
#' 
#' 
#' @export
#'
#' 
get_exampledata <- function() {
    file.copy(system.file("extdata/2014-07-22_CHO hERG.dat", package = "ephys2"), getwd())
    file.copy(system.file("extdata/VG_Blocker.dat", package = "ephys2"), getwd())
    file.copy(system.file("extdata/120911/VG_Blocker_1.xls", package = "ephys2"), getwd())
    
    file.copy(system.file("extdata/CURSORS", package = "ephys2"), getwd())
    file.copy(system.file("extdata/render_exp.R", package = "ephys2"), getwd())
    file.copy(system.file("extdata/render_ser.R", package = "ephys2"), getwd())
    load("CURSORS", .GlobalEnv)  
}

example_ <- function() {
  require(ephys2)
  require(shiny)
  require(shinyTree)
  
    options(shiny.launch.browser = .rs.invokeShinyPaneViewer)
    get_exampledata()
    tree <- reorder_tree(get_treeinfo("2014-07-22_CHO hERG.dat"), 1:3)
    tree <- showtree(tree)
}
tdanker/ephys2 documentation built on Aug. 11, 2019, 12:12 p.m.