Skip to content

Instantly share code, notes, and snippets.

View muschellij2's full-sized avatar

John Muschelli muschellij2

View GitHub Profile
library(oro.dicom)
library(oro.nifti)
library(shiny)
library(shinyIncubator)
options(shiny.maxRequestSize = -1)
shinyServer(function(input, output, session) {
# output$filetable <- renderTable({
makenii = reactive({
rimg = c(0, 100)
nii = NULL
#' @title <brief desc>
#'
#' @description <full description>
#' @param <what param does>
#' @param <what param does>
#' @param <what param does>
#' @export
#' @keywords
#' @seealso
#' @return
@muschellij2
muschellij2 / gist:c1bdc1cd48954d86b46e
Created May 1, 2014 14:06
Example of Roxygen markdown
#' @name fslmask
#' @title Mask image using FSL
#' @param file (character) image to be masked
#' @param mask (character) mask given for image
#' @param outfile (character) resultant masked image name
#' @param retimg (logical) return image of class nifti
#' @param reorient (logical) If retimg, should file be reoriented when read in?
#' Passed to \code{\link{readNIfTI}}.
#' @param intern (logical) to be passed to \code{\link{system}}
#' @param opts (character) additional options to be passed to fslmask
@muschellij2
muschellij2 / gist:a77c2316421990177001
Created May 2, 2014 16:06
Coefficients from model
> t(t(coef(SuBLIME_model)))
[,1]
(Intercept) -9.828049e+00
FLAIR 6.859367e-01
PD 7.665177e-01
T2 -3.484273e-01
T1 5.850592e-01
FLAIR_diff 1.699155e-01
time_diff 2.533482e-03
PD_diff 3.295134e-01
So day 2 of the #JHUSMARTHack was last week, but I figured this would be a good time to discuss what was accomplished, but really discuss why I like using [RStudio](http://www.rstudio.com/) for making packages.
# What was accomplished?
I had spoken [before](http://hopstat.wordpress.com/2014/05/01/smart-hackathon-day-1/) about the [repositories](http://github.com/muschellij2/) I had worked on an also [Developing Packages in RStudio](http://www.rstudio.com/ide/docs/packages/overview). I'll discuss the workflow I settled into for for making a package.
## Workflow for an `R` package
I'm assuming `R` code is already available, presumably functions you had created during a project or analysis. If code is not available, GREAT! You can start your workflow for your new package or product all the same. I'll try to put command-line equivalents in double parentheses.
Workflow:
@muschellij2
muschellij2 / gist:b3b803df7a4cd165dbd4
Last active August 29, 2015 14:02
Quick updown histogram
library(ggplot2)
df = data.frame(x = rnorm(100), x2 = rnorm(100, mean=2))
g = ggplot(df, aes(x)) + geom_histogram( aes(x = x, y = ..density..), fill="blue") +
geom_histogram( aes(x = x2, y = -..density..), fill= "green")
print(g)
## using base
h1 = hist(df$x)
h2 = hist(df$x2)
@muschellij2
muschellij2 / run_matlab.R
Created August 15, 2014 15:19
Matlab code needed for running in R
#' @title Find matlab path
#'
#' @description This tries to find matlab's path using a system which
#' command, and then, if not found, looks at \code{getOption("matlab.path")}. If not path is found, it fails.
#' @export
#' @return Character of command for matlab
get_matlab = function(){
find.matlab <- system("which matlab", ignore.stdout=TRUE)
matcmd <- 'matlab -nodesktop -nosplash -nodisplay -r '
if (find.matlab != 0){
<style type="text/css">
body {
background-image: url('figure/rplot_loess.png');
background-color: #cccccc;
}
</style>
@muschellij2
muschellij2 / gist:eb81726d3c51011815fe
Created November 4, 2014 02:26
Simple function to take DESCRIPTION file and make sure title case for CRAN submission
title_desc = function(file) {
require(Hmisc)
desc = read.dcf(file)
title = desc[, "Title"]
ss = strsplit(title, " ")[[1]]
ss = capitalize(ss)
ss = paste(ss, collapse = " ")
desc[, "Title"] = ss
write.dcf(desc, file=file)
}