Skip to content

Instantly share code, notes, and snippets.

View mattjbayly's full-sized avatar

Matthew Bayly mattjbayly

View GitHub Profile
@mattjbayly
mattjbayly / Replace_multiple_strings.R
Last active October 16, 2022 05:42
Replace multiple strings across multiple text files
#' Replace multiple strings across multiple files with original values and replacement values.
#'
#' files - A character string of file names to work through.
#' f - A character string of original values that you want to replace.
#' r - A character string of replacement values (f->r).
multi_replace <- function(files="", f="", r=""){
file_line = data.frame() # (optional) tracking table
#loop through each file separately
for(j in 1:length(files)){
nl <- suppressWarnings(readLines(files[j])) # read file line by line
@mattjbayly
mattjbayly / Find_Php_String_In_Php_Files.R
Created August 12, 2016 15:37
Find the occurence and count of occurence for a text string across php files
#' Find the occurence and count of occurence for a text string across php files.
#'
#' @param path A path directory to search in containing php files of interest.
#' @param files A list of files to search within.
#' @param search_for A text string to search for within php files.
#' @return The count of \code{search_for} occurences across php \code{files}.
#' @examples
#' # Define main root directories to search within
#' foldergroup <- "C:/Users/me/Desktop"
#' # Specify the phrase to search for
@mattjbayly
mattjbayly / make glmmADMB work.R
Created October 7, 2016 00:21
quick get the glmmADMB package working on Cora's computer
install.packages("R2admb")
install.packages("glmmADMB",
repos=c("http://glmmadmb.r-forge.r-project.org/repos",
getOption("repos")),
type="source")
# does this works!
# R 3.3.1 & R 3.0.0
library(glmmADMB)
################################################
# Match two strings in any order:
'hi jack here is james'
'hi james here is jack'
^(?=.*\bjack\b)(?=.*\bjames\b).*$
################################################
# Match two strings with anything in between:
'hi jack here is james'
@mattjbayly
mattjbayly / RastObjAlign
Last active January 30, 2018 06:33
Aligns new img with x guidelines for plotting a new png over an older one
RastObjAlign <- function(
h_aling=TRUE,
bg_rast=NA,
orig_width_in=11,
orig_height_in=8.5,
insert_img=NA,
x_pos_cent_set=NA,
y_pos_bottom_set=NA
# Get Dimensions in Inkscape with Ctrl+Shift+E export png image
){
@mattjbayly
mattjbayly / ScaleBar
Created January 30, 2018 07:28
R scale bar for sf plots
ScaleBarR <- function(
start_x=NA,
start_y=NA,
dist=NA,
source_prj=NA,
scale_prj=32610
){
dd <- data.frame(x=start_x, y=start_y, id=1)
coordinates(dd) <- ~x+y