This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The following imports a long list of csv's fast using lapply and read_csv: | |
# File list: | |
data.files <- list.files(production.dataset(Universe,"EQS"),pattern = "*.csv",full.names=TRUE, recursive = FALSE, include.dirs = FALSE) | |
# Import all the files as separate lists | |
df.eqs <- lapply( data.files, function(x) read_csv(x)) | |
# Append the files by row: | |
x <- df.eqs[[1]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Following [this](https://plot.ly/r/getting-started/) howto, go [here](https://plot.ly/) and sign up using github. | |
Once this has been done, take not of your username (same as github) and api key. | |
Then go to R and use the following code. | |
install.packages("viridis") # dependency | |
install.packages("devtools") | |
devtools::install_github("ropensci/plotly") | |
library(plotly) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
We uuse GSUB to change parts of a string. | |
This is particularly useful if we want to replace parts of a word or phrase. | |
It can be used as follows to, e.g., replace all the '/' by a '_' in data: | |
data[y,z]<-gsub("/","_", data[y,z]) | |
To remove all parts of a string after a sign, we can also use gsub. | |
E.g., if we have naming conventions such as: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
devtools::install_github("hadley/ggplot2") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://statmodeling.com/best-way-to-add-a-footnote-to-a-plot-created-with-ggplot2.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
R can execute scripts automaticall and at specific times. | |
See [this](http://www.r-bloggers.com/scheduling-r-markdown-reports-via-email/?utm_source=feedburner&utm_medium=email&utm_campaign=Feed%3A+RBloggers+%28R+bloggers%29) to see how to generate automated r scripts and emails with Rmarkdowns. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Adjusting the documentation of ?suppressWarning to only suppress a very specific warning, e.g. if we know a function will warn about zero standard deviation: | |
foo <- function() { | |
x <- cor( c(1,1,1,1,1),c(1:5),method = 'spearman',use = "pairwise.complete.obs") | |
} | |
x <- foo() # This produces the warning: "the standard deviation is zero" | |
To suppress this warning when running foo(), wrap it with the following function: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SetNames allows a mutate function to design a formula and rename the new mutated column accordingly. It works perfectly well across vectors as well. | |
Another benefit is that setNames can then also be run to check the formula: | |
E.g. to create a % column for Variable: | |
Variable <- "FactorX" | |
DF %>% | |
mutate_(.dots = | |
setNames( paste0(Variable,"/sum(",Variable,", na.rm = TRUE))"), paste0(Variable, "Pct")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
If a new package needs to be included into the knitr defaults, use the following process: | |
Download the package's .tar file and drop it into: (either download this, or find it in: C:\Program Files (x86)\MiKTeX 2.9\source after installing it using programs/miktex/packagemanager) | |
C:\Program Files\Microsoft\MRO\R-3.2.3\library\knitr\misc | |
A large number of Tarfiles are located here: https://www.ctan.org/tex-archive/systems/win32/miktex/tm/packages?lang=en | |
To find your knitr folder, type in R: path.package() | |
Now add the \usepackage command to the default tex file and it can now be used inside rmarkdown by calling the function as follows (for e.g. adjumulticol package): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is a useful means of using vector inputs in filters for dplyr: | |
Function_Name <- lazyeval::interp(~Function(a), a = as.name(VectorInput)) | |
df %>% | |
filter_(Function_Name) | |
This applies the Function on the VectorInput to a filter. | |
E.g., to get complete cases for a vector, use: |
OlderNewer