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
# Trying to find a basic test for dates in R. was looking for a is.Date like as.Date vibe | |
IsDate <- function(mydate, date.format = "%d/%m/%y") { | |
# Check if field is a date using as.Date that looks for unambiguous dates | |
# Assumes date format so NA returned not Character error. | |
# Why? with no date format, R tries two defaults then gives error. | |
# BUT With a dateformat R returns NA | |
# Args | |
# Suspected date and optional date format string | |
# Returns |
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
# examples of issues with indexing with dates for will turn to number | |
# Solution | |
# - DONT use dates as elements of your index | |
# - DO index alonmg length of your date list | |
library(data.table) | |
date.list <- c(as.Date("2015/3/1"), as.Date("2015/3/2")) | |
# 1 loop through dates? | |
for (i.date in unique(date.list)){ |
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
# Identify what machine you are running on in R | |
# Use [[ to get the name out of entry | |
# Help from http://r.789695.n4.nabble.com/computer-name-td3593120.html | |
k.machine.name <- Sys.info()[["nodename"]] | |
k.dir.proj = "C:/Users/Michael/GitHub/FVCA" #ALIEN | |
if (identical(k.machine.name, "FVCA-BLOOMBERG")) { | |
k.dir.proj <- "C:/Users/Info/Documents/GitHub/FVCA" #FVCA-BLOOMBERG OVERRIDE | |
} |
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
# Comparing data tables examples | |
# Examples from | |
# http://cran.r-project.org/web/packages/data.table/data.table.pdf | |
# page 14 | |
library(data.table) | |
dt1 <- data.table(A = letters[1:10], X = 1:10, key = "A") # a to j | |
dt2 <- data.table(A = letters[5:14], Y = 1:10, key = "A") # e to n | |
identical(all.equal(dt1, dt1), TRUE) |
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
# Test rbind | |
# Kudos to http://stackoverflow.com/questions/15014339/rbind-with-new-columns-and-data-table | |
# old log | |
dt.1 <- data.table(message = c("A-ok", "no", "yes"), | |
date = c("Feb", "Mar", "Mar")) | |
# new log more columns | |
dt.2 <- data.table(message = c("watch"), | |
rows.added = c(100), |
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
library(data.table) | |
dt <- data.table(name = c("M","P","S"), | |
pet = c("dog","cat","fish")) | |
# famous question can be simple | |
# http://stackoverflow.com/questions/12328056/how-do-i-delete-rows-in-a-data-frame | |
dt <- dt[-c(1:2),] | |
# Note it is called subsetting |
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
# Fix TZ showing in tables : drawdown Shiny example | |
# micstr 4 July 2017 | |
# shiny 0.12. broke the perfapp drawdown tables now showing dates with Timezone e.g. | |
# 2016-04-30T00:00:00Z | |
#"POSIXt objects are now serialized to JSON in UTC8601 format (like | |
#"2015-03-20T20:00:00Z"), instead of as seconds from the epoch. If you | |
#have a Shiny app which uses sendCustomMessage() to send datetime | |
#(POSIXt) objects, then you may need to modify your Javascript code to | |
#receive time data in this format." |
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
# Test app chartlabels missing fixes | |
# (mcve Smaller subset version with no source) | |
suppressPackageStartupMessages(library(data.table)) | |
suppressPackageStartupMessages(library(googleVis)) # else get startup msg | |
library(shiny) | |
# FUNCTIONS | |
# Simplifying output | |
drawGraphAndTable <- function(title, name) |
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
# Logging use of tictoc notes | |
# See https://stackoverflow.com/a/47954069/4606130 | |
# https://www.jumpingrivers.com/blog/timing-in-r/#the-tictoc-package | |
tic("timer") | |
1+1 | |
# When log = TRUE, toc() pushes the measured timing to a list | |
# quiet = TRUE prevents from printing the timing |
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
# Thanks to David https://stackoverflow.com/a/54922170/4606130 | |
# date range input set to month with minview | |
# https://stackoverflow.com/a/54922170/4606130 | |
dateInput2 <- function(inputId, label, minview = "days", maxview = "decades", ...) { | |
d <- shiny::dateInput(inputId, label, ...) | |
d$children[[2L]]$attribs[["data-date-min-view-mode"]] <- minview | |
d$children[[2L]]$attribs[["data-date-max-view-mode"]] <- maxview |
OlderNewer