Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

Styles do not read in correctly in certain circumstances #88

Closed
RobinL opened this issue Oct 11, 2017 · 3 comments
Closed

Styles do not read in correctly in certain circumstances #88

RobinL opened this issue Oct 11, 2017 · 3 comments

Comments

@RobinL
Copy link
Member

RobinL commented Oct 11, 2017

This file doesn't work:

https://github.com/moj-analytical-services/OMSQ_Tables_/blob/b92577d6a58de2739ebeb63773e901f2443a04ce/STYLES.xlsx

Reproduce the problem with this code:

library(xltabr)

path <- system.file("extdata", "synthetic_data.csv", package="xltabr")
xltabr::set_style_path("styles2.xlsx")

df <- read.csv(path, stringsAsFactors = FALSE)
ct <- reshape2::dcast(df, drive + age  ~ type, value.var= "value", margins=c("drive", "age"), fun.aggregate = sum)

ct <- dplyr::arrange(ct, -row_number())

titles = c("Breakdown of car statistics", "Cross tabulation of drive and age against type*")
footers = "*age as of January 2015"
tab <- xltabr::auto_crosstab_to_wb(ct, titles = titles, footers = footers, return_tab = TRUE)

tab$style_catalogue$title
tab$title

openxlsx::openXL(tab$wb)
@RobinL
Copy link
Member Author

RobinL commented Oct 11, 2017

tab$style_catalogue[[value]] <- style_key

Because a list can be accessed by number or by index, this overwrites a style if value is a number

So for instance, if a cell anywhere has the number 3 in it, and the 3rd item in the list is title, then the title will be overwritten

@RobinL
Copy link
Member Author

RobinL commented Oct 11, 2017

Note the underlying problem was essentialy this

> a <- list()
> a[[1]] <- 100
> a[["1"]] <- 20
> a
[[1]]
[1] 100

$`1`
[1] 20

> a <- list()
> a[["1"]] <- 20
> a[[1]] <- 100
> a
$`1`
[1] 100

@RobinL
Copy link
Member Author

RobinL commented Oct 12, 2017

Closed by #89

@RobinL RobinL closed this as completed Oct 12, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant