Skip to content

Instantly share code, notes, and snippets.

View CNuge's full-sized avatar

Cam Nugent CNuge

View GitHub Profile
@CNuge
CNuge / intro_to_r_functions.rmd
Last active October 25, 2019 10:32
R markdown file corresponding to blog post, for local execution of code. source: https://cnuge.github.io/post/functions_in_r/
---
title: "An introduction to using functions in R"
author: "Cameron M. Nugent"
date: "2019-10-17"
---
## Introduction
R is considered to be a functional programming language. What this means is that the syntax and rules of the language are most effective when you write code built around the use of functions. They allow you to modularize code, thereby isolating different blocks in a way that makes your code more generalized, reuseable, readable and easier to debug. This post is meant to introduce the three basic parts of a function (the arguments, the body and the environment), demonstrate some of the rules that govern function behaviour and provide a launchpad to help you get started writing functions in your own R code.
@CNuge
CNuge / multiple_outputs.r
Created November 8, 2018 20:45
A quick walkthrough of how to have a function return multiple values in r
# for a recent tutorial at the university of guelph R users group, I was going through
# how to generate summary stats & tidy dataframes from messy data sources
# we were working with text data, and the exercise I designed called for us to process
# a series of sentences and answer 3 questions about each line:
# is the line dialouge (by presence of a quotation mark)
# is the line a question (by presence of a question mark) and
# what is the word count of the line
@CNuge
CNuge / chromosome_plot.ipynb
Last active October 1, 2022 11:13
A short explanation of how I visualize genome wide data
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@CNuge
CNuge / py_kwarg_decorator_examples.py
Last active April 6, 2018 00:12
python decorator factory to alter error messages thrown by function initialization
#original undecorated
class example_class:
def __init__(self, *, kw1 = None, kw2 = None):
if kw1 is not None or kw2 is not None:
#do stuff with the args
self.kw1 = kw1
self.kw2 = kw2
def read(self, *, kw1 = None, kw2 = None):
if kw1 is not None or kw2 is not None:
# ORIGINAL version
def merge_sorted(list_a, list_b):
""" take two lists of integers sorted smallest to largest,
merge them to a single output list with
no duplicate values """
output_list = []
@CNuge
CNuge / genome_metadata.ipynb
Last active March 8, 2018 15:01
GC content and Size of sequenced genomes on NCBI
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@CNuge
CNuge / getSandP_threaded.py
Last active February 1, 2021 12:11
Multithreading modification of the S&P 500 data downloader
from datetime import datetime
from concurrent import futures
import pandas as pd
from pandas import DataFrame
import pandas_datareader.data as web
def download_stock(stock):
""" try to query the iex for a stock, if failed note with print """
try:
@CNuge
CNuge / getSandP_original.py
Last active February 1, 2021 12:11
Original S&P 500 data downloader
from datetime import datetime
import pandas as pd
from pandas import DataFrame
import pandas_datareader.data as web
def download_stock(stock):
""" try to query the iex for a stock, if failed note with print """
try:
print(stock)
@CNuge
CNuge / feature_engineering.ipynb
Created January 16, 2018 14:23
Feature engineering for California house price prediction
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@CNuge
CNuge / machine_learning_r_pt2.ipynb
Last active December 14, 2017 19:38
Gradient Boosting and Parameter Tuning in R
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.