Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes coerce from xts where a column x was present #4898

Merged
merged 2 commits into from
May 25, 2021
Merged

fixes coerce from xts where a column x was present #4898

merged 2 commits into from
May 25, 2021

Conversation

jangorecki
Copy link
Member

@jangorecki jangorecki commented Feb 11, 2021

closes #4897
could be resolved more nicely having #4304 merged before

@codecov
Copy link

codecov bot commented Feb 11, 2021

Codecov Report

Merging #4898 (9bb8ce4) into master (c179b5e) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #4898   +/-   ##
=======================================
  Coverage   99.47%   99.47%           
=======================================
  Files          75       75           
  Lines       14789    14844   +55     
=======================================
+ Hits        14711    14766   +55     
  Misses         78       78           
Impacted Files Coverage Δ
R/xts.R 100.00% <100.00%> (ø)
R/fmelt.R 100.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c179b5e...9bb8ce4. Read the comment docs.

@mattdowle mattdowle added this to the 1.14.1 milestone May 23, 2021
@mattdowle mattdowle changed the title fixes coerce from xts where a column x was present, closes #4897 fixes coerce from xts where a column x was present May 25, 2021
@mattdowle mattdowle merged commit 0c1e9cd into master May 25, 2021
@mattdowle mattdowle deleted the xts-x branch May 25, 2021 09:12
@@ -8,7 +8,7 @@ as.data.table.xts = function(x, keep.rownames = TRUE, key=NULL, ...) {
if (identical(keep.rownames, FALSE)) return(r[])
index_nm = if (is.character(keep.rownames)) keep.rownames else "index"
if (index_nm %chin% names(x)) stop(domain=NA, gettextf("Input xts object should not have '%s' column because it would result in duplicate column names. Rename '%s' column in xts or use `keep.rownames` to change the index column name.", index_nm, index_nm))
r[, c(index_nm) := zoo::index(x)]
r[, c(index_nm) := zoo::index(x), env=list(x=x)]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattdowle Great to use that you are using new feature. For future I would suggest to apply some styling preferences that will more easily convey which variables are substituted. So far I used to just prefix them with dot.

r[, c(index_nm) := zoo::index(.x), env=list(.x=x)]

but I am open for any other alternative. It is not really needed because there is no collision, but for readability it could be useful.

Copy link
Member

@mattdowle mattdowle May 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is a downside of this approach: the repetition of the variable names. Using .x actually means more like ..x already does and the . vs .. could be confusing; i.e. . conveys current level, and .. conveys one level up, but not here where env= is used if we follow this single . prefix style.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

as.data.table.xts(foo) gives wrong index values when 'x' is in the column names.
2 participants