R/addin.R

Defines functions insert_header_addin

Documented in insert_header_addin

#' Insert header for analysis script
#'
#' Note, the first time you use this addin, you will be prompted to
#' enter your name and your email. After submitting this information,
#' restart your R session to use this addin. Alternatively, one can
#' add ANALYST_NAME and ANALYST_EMAIL to ~/.Renviron.
#' @export
insert_header_addin <- function() {
  analyst_name <- Sys.getenv("ANALYST_NAME")
  analyst_email <- Sys.getenv("ANALYST_EMAIL")
  if (analyst_name == "") {
    analyst_name <- readline(prompt="Enter your first and last name: ")
    write(paste0('ANALYST_NAME=', analyst_name), file = '~/.Renviron', append = T)
    analyst_name <- 'Analyst name'
    print("Added ANALYST_NAME evironment variable to .Renviron.")
  }
  if (analyst_email == "") {
    analyst_email <- readline(prompt="Enter your email address: ")
    write(paste0('ANALYST_EMAIL=', analyst_email), file = '~/.Renviron', append = T)
    print("Added ANALYST_EMAIL environment variable to .Renviron")
    stop("Added environment variables to ~/.Renviron. Restart your R session to use this Addin.")
  }
  
  rstudioapi::insertText(
    paste0("# Assay name\n",
           
           "# ", analyst_name, " ", analyst_email, "\n",
           paste0("# ", Sys.Date()),"
# ====================================
library(ggplot2)     ## Plots
library(assayr2)     ## HemoShear assay analysis tools
library(purrr)       ## Functional programming constructs (map, map2)
library(magrittr)    ## Functional programming constructs (%>%, %<>%)
library(drc)         ## Dose-response curves, useful for fitting standard curves
library(lme4)        ## Mixed-effects models
library(openxlsx)    ## Read excel files
library(boxr)        ## Access Box from R (see the following website if you have never used boxr)
                     ##     https://cran.r-project.org/web/packages/boxr/vignettes/boxr.html
library(tidyr)       ## only for nest_legacy and unnest_legacy
library(dplyr)       ## Data manipulation


options(stringsAsFactors = FALSE)
## Set ggplot2 theme
theme_set(assayr2::theme_assayr())
## Create directory for input data and results
outdirs <- c('data', 'results')
for (d in outdirs) {
  if (!(dir.exists(d))) {
    dir.create(d)
  }
}
## Set this to the integer that is the Box directory ID
BOX_INDIR <- 
## Create folder on box to upload results
BOX_OUTDIR <-
## Authenticate with Box
boxr::box_auth()
## Download input data 
boxr::box_fetch(BOX_INDIR, 'data')

# Globals =============================
PLATE_LAYOUT <- ''
RAW_DATA <- c('')

# Data cleaning =======================
## Metadata

## Plate layout  

## Raw data

# QC ==================================

# Analysis ============================

# Reporting ===========================

## Upload results to Box
# boxr::box_push(BOX_OUTDIR, 'results', overwrite=T)

## Save current directory to Box, which should include
# R script, copy of input data, and R session info. 

# assayr2::box_archive(BOX_OUTDIR, 'AssayName.zip')

"
    ))
}
hemoshear/assayr2 documentation built on Nov. 8, 2019, 6:13 p.m.