KentonWhite / ProjectTemplate

A template utility for R projects that provides a skeletal project.
http://projecttemplate.net
GNU General Public License v3.0
623 stars 159 forks source link

data.frames not converting to data.tables #264

Closed UTexas80 closed 6 years ago

UTexas80 commented 6 years ago

Report an Issue / Request a Feature

I'm submitting a (Check one with "x") :


Issue Severity Classification -

(Check one with "x") :

Expected Behavior
Using the global.dcf in the configs folder, I expect my data.frames which are defined in the data folder to be converted into data.tables ##### Current Behavior The data frames don't convert ##### Steps to Reproduce Behavior my global.dcf is set as follows version: 0.8.2 data_loading: TRUE data_loading_header: TRUE data_ignore: cache_loading: FALSE recursive_loading: TRUE munging: TRUE logging: TRUE logging_level: INFO load_libraries: TRUE libraries: BatchGetSymbols, caTools, curl, DataExplorer, data.table, devtools, dplyr, filesstrings, FinancialInstrument, foreach, fTrading, ggplot2, ggthemes, here, igraph, knitr, lubridate, modules, openxlsx, PerformanceAnalytics, plotly, plyr, Quandl, quantmod, quantstrat, readxl, reshape, reshape2, rio, rJava, rprojroot, skimr, SIT, SIT.date, stringr, tibble, tidyquant, timetk, TTR, xlsx, zoo as_factors: FALSE data_tables: TRUE attach_internal_libraries: FALSE cache_loaded_data: FALSE sticky_variables: NONE `insert short code snippets here` library(tidyquant) # Loads tidyquant, tidyverse, lubridate, quantmod, TTR, and xts library(TTR) # Technical Trading Rules package # SPL Processing -- SPL <- tq_get("SPL.AX") # Get SPL Stock Prices SPL<-SPL[complete.cases(SPL),] # Delete NA date <- SPL$date # Create date variable key<-paste(as.character(format(date, "%Y")), as.character(format(date, "%m")), as.character(format(date, "%d")), "spl", sep = "") # TTR Processing -- adx <- ADX(SPL[,c("high","low","close")]) # Welles Wilder’s ZLEMA is similar to an EMA, as it gives more weight to recent observations, but attempts to remove lag by subtracting data prior to (n-1)/2 periods (default) to minimize the cumulative effect. # Create Table -- tblTrendADX <- data.frame(key,date,"spl",adx) # Create Welles Wilder's ADX Table ##### Screenshots
Version Information
0.8.2 ##### Possible Solution
KentonWhite commented 6 years ago

Can you clarify something for me please? When you say "data.frames which are defined in the data folder " do you mean that a data.frame is saved in the data folder as an RData file? Or do you mean that an .R script in the data folder creates the data.frame?

UTexas80 commented 6 years ago

I apologize for the confusion. I mean that there is an .R script in the data folder creates the data.frame? For example, in my .R script is the following code:

tblPrice <- data.frame(key,SPL,"spl", date + 1)

After the project template process completes, when I run the is.data.table(tblPrice) command it returns 'FALSE'

KentonWhite commented 6 years ago

The flag data_tables: TRUE is for data structures that ProjectTemplate creates, like loading csv files or importing from a sql database. When you run your own script in the data folder, the output is saved in the format created in the script. So in your case, since the tblPrice is constructed as a data.frame, it will remain a data.frame — ProjectTemplate won't convert it. If you need it as a data.table, you will need to convert it to a data.table from the script.

UTexas80 commented 6 years ago

Thank you Kenton. Chalk it up to my newbie status. Live and learn. Take care, Glen

On Fri, May 25, 2018 at 9:09 AM, Kenton White notifications@github.com wrote:

The flag data_tables: TRUE is for data structures that ProjectTemplate creates, like loading csv files or importing from a sql database. When you run your own script in the data folder, the output is saved in the format created in the script. So in your case, since the tblPrice is constructed as a data.frame, it will remain a data.frame — ProjectTemplate won't convert it. If you need it as a data.table, you will need to convert it to a data.table from the script.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/KentonWhite/ProjectTemplate/issues/264#issuecomment-392052657, or mute the thread https://github.com/notifications/unsubscribe-auth/APWzEYJOExRWmEIz4p0RwRD6gssIelZLks5t2AJ-gaJpZM4UKrB0 .