Skip to content

Instantly share code, notes, and snippets.

@harveyl888
harveyl888 / get_params.R
Created June 28, 2022 11:48
extract parameters from roxygen metadata tag
#' extract parameters from roxygen tags
#'
#' extract parameters from roxygen tags
#'
#' @param n Namespace
#' @param f Function
#'
#' @importFrom tools Rd_db
#' @importFrom jsonlite fromJSON
#'
@harveyl888
harveyl888 / shiny_asynchronous_process.R
Created March 30, 2017 13:08
Shiny - Running a complex process asynchronously to avoid tying up the UI
## Data creation
##
## Create a large Excel spreadsheet as a asynchronous process
##
library(shiny)
## Temporary files to store log, script, rds data and excel output
logfile <- tempfile()
scriptfile <- tempfile()
@harveyl888
harveyl888 / shiny_single_process.R
Created March 30, 2017 13:06
Shiny - Running a complex process ties up the UI
## Data creation
##
## Create a large Excel spreadsheet within a Shiny app
##
library(shiny)
library(openxlsx)
## Create a dummy matrix
@harveyl888
harveyl888 / manage_users_with_encryption.R
Created March 30, 2017 12:37
Manage users with encryption (R Shiny App)
## Authentication
## This is a small app to demonstrate user-managed authentication using a hash to encode passwords.
## Users are stored in a SQL database with passwords along with roles.
## Once a user is logged in the shiny app responds to the user's role.
## In order to use in a real setting, additional code for password management,
## changing and resetting would need to be implemented.
library(shiny)
library(RSQLite)
library(sodium)
@harveyl888
harveyl888 / manage_users_no_encryption.R
Created March 30, 2017 12:36
Manage users without encryption (R Shiny App)
## Authentication
## This is a small app to demonstrate user-managed authentication without encoded passwords.
## Users are stored in a SQL database with passwords along with roles.
## Once a user is logged in the shiny app responds to the user's role.
## In order to use in a real setting, additional code for password management,
## changing and resetting would need to be implemented.
library(shiny)
library(RSQLite)
Player Team Points Cost Pos
Cech Arsenal 159 £5.5 GLK
Courtois Chelsea 69 £5.5 GLK
Hart Man City 134 £5.5 GLK
de Gea Man Utd 142 £5.5 GLK
Lloris Spurs 140 £5.5 GLK
Ospina Arsenal 20 £5.0 GLK
Begovic Chelsea 55 £5.0 GLK
Robles Everton 46 £5.0 GLK
Stekelenburg Everton 57 £5.0 GLK
@harveyl888
harveyl888 / scrape hmdb hml list.R
Last active March 25, 2016 00:59
Scraping HML
##
## Scraping HML
## use follow_link to read subsequent pages
## continue reading and scraping tables until 'Next' link does not respond
## table scraped by column so that max information can be teased out
##
library(rvest)
library(data.table)
@harveyl888
harveyl888 / beerList.R
Created January 30, 2016 12:18
Scrape lists of breweries and beers from Craft Beer Cellar
##
## beerList
##
library(xml2)
library(stringr)
##url <- "http://www.craftbeercellar.com/belmont/beers.php?sort=country" ## Belmont location
url <- "http://www.craftbeercellar.com/winchester/beers.php?sort=country" ## Winchester location
html <- read_html(url)
@harveyl888
harveyl888 / transferWatch.R
Last active August 28, 2016 03:06
Monitor fantasy premierleague player list for updates during transfer window. Send notification via pushbullet when a new player is added.
##
## transferWatch
##
## Monitor fantasy premierleague player list for updates during transfer window.
## Send a pushbullet notification when the player list has changed.
## Run as a cron job to send updates at regular intervals
##
## crontab:
## 0 * * * * Rscript $HOME/codes/transferWatch/transferWatch.R
## run every hour