Does fasttime cache values outside of it's environment? If so, why?

只谈情不闲聊 提交于 2019-12-25 02:56:12

问题


DISCLAIMER: I assume 'cache' and 'environment' are the right words here, though I am new to programming, so I may have misunderstood the terminology.

I have recently been trying to get to grips with the package fasttime for R, and I realise know there it has a behavior that I've not seem in documentation and also has been the root of my problems getting it to function.

TL;DR - If I use fast time to convert to POSIXct from a parent object into child one, then use it in a different way to calculate from the intact parent to child 2, child two will always have the result of child two, even if they should be different when calculated entirely independently.

Long version -

I have a long list of dates and times as characters to convert into POSIX (see this question)

And example data set and working file can be found here.

When I read the example file I need to build a single DateTime column, then convert it to POSIXct.

First I read:

setwd("~/GitHub/fasttimeError")

example <- fread("datesAndTimes.csv")
# read example file of dates and times

Then I paste:

example[ , DateTime := paste(ConsumptionDate, variable)]
# paste dates with times to make DateTime single column for POSIX conversion

Then I attempt to convert:

library(fasttime)
# load library for fastPOSIXct

test1 <- example[ , DateTime := fastPOSIXct(x = DateTime)]
# this will read the data as starting in 2006

test2 <- example[ , DateTime := fastPOSIXct(sub('(\\d*)/(\\d*)/(\\d*) (.*)', '\\3-\\1-\\2 \\4', DateTime))]
# this should produce an identical file to test 1

Darn, neither process worked correctly. They both produce a data set starting at 2006.

But for some reason, if I clear the whole working environment (in RStudio), and re run the exact same code but SKIP the line that creates test1, then my object labelled test2 converts perfectly.

Why?

来源:https://stackoverflow.com/questions/29892116/does-fasttime-cache-values-outside-of-its-environment-if-so-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!