r

Why is there a delay in getting opening trade price using quantmod

社会主义新天地 提交于 2021-02-19 07:01:06
问题 I'm using quantmod package for my trading but in the last few days I get a delay in getting the open daily price ( SPY ) when I run my code on market open time 9:30 AM EST. After about 10 minutes all is working great and I get the numbers but how can I bypass this delay ? Is it because of my code or another reason? I use quantmod Version 0.4-4. # rm(list = ls()) # generally considered as bad manner in an MWE require(quantmod) options(scipen=999) spy <- getSymbols(("SPY") , src = 'yahoo', from

Unzipping a file in R Shiny using unzip() fails when deployed

瘦欲@ 提交于 2021-02-19 06:49:29
问题 I'd like to unzip a compressed .mdb file in the www folder of my shiny app, query it for data, and then remove it. Unzip() works on my local machine, but when I deploy the app at shinyapps.io, it has issues unzipping the file. Because I'm not able to read.table() the resulting file (it's an .mdb) I don't think unz() will work. This code works when run on my local machine Server: require(shiny) shinyServer(function(input, output) { observeEvent(input$run,{ #Run Button dbName=unzip('www/test

Adding zero valued entries so that all groups have entries for the same items

早过忘川 提交于 2021-02-19 06:47:07
问题 I'm trying to use Rcharts to create a stacked bar chart across a number of recorded regions (stacking separate group values on top of each other). The data is in a format similar to below. Region | Group | Value ---------------------- USA | A | 5 USA | B | 3 USA | C | 1 UK | A | 4 UK | B | 6 France | C | 3 Using the below code produces a grouped bar chart which works fine. However the stacked button does nothing to change the plot. nPlot(Value ~ Region, group = 'Group', data = example_data,

Unicode Variable Names in R

≯℡__Kan透↙ 提交于 2021-02-19 06:35:45
问题 I was working on a toy project and tried using some unicode variable names to match a paper I was attempting to implement. The following code works fine on R 3.4.3 on Windows (RStudio version 1.1.456) and R 3.5.1 on OSX: > µ <- function(ß, n) ß * n > µ(2, 3) [1] 6 This code gives the following error, with α typed as ALT+224: > α <- 2 Error: unexpected input in "\" The file was saved as UTF-8, so this is surprising to me. make.names is consistent with the results above: > make.names('µ') [1]

Converting LaTeX tables into R dataframes/matrices

坚强是说给别人听的谎言 提交于 2021-02-19 06:27:05
问题 The process of converting R outputs into LaTeX is well documented. However, the opposite not so much. The problem: I have a long LaTeX file and would like to import the tables it into R (say, convert them as data frames). Question: is there an elegant/efficient way of doing this task without having to do it manually? Note that there are percent signs (%) commenting the rows in the tables. For example, \documentclass{article} \usepackage[utf8]{inputenc} \usepackage{natbib} \title{Processing

Microbenchmarking base R and three packages on string pattern substitution

妖精的绣舞 提交于 2021-02-19 06:25:44
问题 My question is whether my method and conclusion are correct. As part of my learning regular expressions, I wanted to figure out in which order to learn the various alternatives (base R and packages). I thought it might help to learn the relative speeds of the alternative functions. So, I created a string vector and called what I hope are equivalent expressions. sites <- c("http://grand.test.com/", "https://example.com/", "http://.big.time.bhfs.com/", "http://test.blogs.mvalaw.com/") vec <-

Link R shiny selectInput item to open file actionButton

跟風遠走 提交于 2021-02-19 06:22:48
问题 Using R shiny, is it possible to link selectInput item to open file action button ? I would like to adapt onclick argument of action button to achieve it. Please find below a reproductible example: Supposing we have "file_1.pdf" and "file_2.pdf" on "www" folder, how can I open the file corresponding to select Input choice ? library(shinydashboard) library(shiny) ui <- dashboardPage( dashboardHeader(title = "Open file app"), dashboardSidebar(), dashboardBody( fluidRow( selectInput(inputId =

R: Adding two matrices with different dimensions based on columns

时光怂恿深爱的人放手 提交于 2021-02-19 06:22:34
问题 I have 22 matrices having equal number of rows (i.e. 691) and different number of columns (i.e. 22-25). I have to add the values corresponding to same row, same column in each of the matrices resulting in one single matrix of the dimension 691*25. fullanno1 has 691 rows & 25 columns: >colnames(fullanno1) [1] "coding-notMod3" "coding-synonymous" "coding-synonymous-near-splice" [4] "intergenic" "intron" "missense" [7] "missense-near-splice" "near-gene-3" "near-gene-5" [10] "splice-3" "splice-5"

R: Adding two matrices with different dimensions based on columns

扶醉桌前 提交于 2021-02-19 06:22:19
问题 I have 22 matrices having equal number of rows (i.e. 691) and different number of columns (i.e. 22-25). I have to add the values corresponding to same row, same column in each of the matrices resulting in one single matrix of the dimension 691*25. fullanno1 has 691 rows & 25 columns: >colnames(fullanno1) [1] "coding-notMod3" "coding-synonymous" "coding-synonymous-near-splice" [4] "intergenic" "intron" "missense" [7] "missense-near-splice" "near-gene-3" "near-gene-5" [10] "splice-3" "splice-5"

R nested map through columns

前提是你 提交于 2021-02-19 06:18:08
问题 I got a function which was solved here. This function takes a column filled with annotations and another grouping column and propagates the annotation to rows with missing values. f1 <- function(data, group_col, expand_col){ data %>% dplyr::group_by({{group_col}}) %>% dplyr::mutate( {{expand_col}} := dplyr::case_when( !is.na({{expand_col}}) ~ {{expand_col}} , any( !is.na({{expand_col}}) ) & is.na({{expand_col}}) ~ paste(unique(unlist(str_split(na.omit({{expand_col}}), " ")) ), collapse = " ")