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

Wb to df cleanup #180

Merged
merged 2 commits into from
May 13, 2022
Merged

Wb to df cleanup #180

merged 2 commits into from
May 13, 2022

Conversation

JanMarvin
Copy link
Owner

@JanMarvin JanMarvin commented May 13, 2022

This cuts the time wasted doing ... nothing. Oh this did cost me almost a day, tweaking back and forth 😄 (I hate optimizing my own code). Though I assume there are a few other places where we simply select something and try to get away with it. (Edit: With other places I mean functions I wrote and with we I mean me ofc 🙈 )

Unit: milliseconds
                                                   expr       min        lq      mean    median        uq       max neval
             wb_old <- openxlsx::loadWorkbook(xlsxFile) 119.04867 122.62752 129.43213 125.08641 128.56099 204.89869    25
                 wb_new <- openxlsx2::wb_load(xlsxFile)  82.15260  83.24123  86.36275  85.13675  86.59532  96.14397    25
    x_old <- openxlsx::read.xlsx(wb_old, sheet = sheet)  11.82465  12.44604  17.24027  12.83931  13.56616  98.14137    25
   x_new <- openxlsx2::read_xlsx(wb_new, sheet = sheet)  39.38849  40.06065  43.35709  40.54560  46.85837  55.08895    25
         openxlsx::saveWorkbook(wb_old, xlsx_old, TRUE) 330.11265 338.87480 364.67391 344.69655 353.43451 536.59185    25
             openxlsx2::wb_save(wb_new, xlsx_new, TRUE) 230.22640 235.91002 249.66324 239.08765 244.97935 336.63808    25
  x_old <- openxlsx::read.xlsx(xlsxFile, sheet = sheet)  78.24407  79.80921  81.53757  80.54667  81.48225  98.49348    25
 x_new <- openxlsx2::read_xlsx(xlsxFile, sheet = sheet)  92.46984  95.17568  99.36759  96.93220 102.30894 111.38240    25


# if (!nrow(cc)) browser()

cc$val <- NA
cc$typ <- NA

cc_tab <- table(cc$c_t)
Copy link
Owner Author

Choose a reason for hiding this comment

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

table() is slow, but not slow enough to be replaced.

sel <- cc$c_t %in% c("b")
cc$val[sel] <- as.logical(as.numeric(cc$v[sel]))
cc$typ[sel] <- "b"
if (isTRUE(cc_tab[c("b")] > 0)) {
Copy link
Owner Author

Choose a reason for hiding this comment

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

in the table there might not be a column "b", therefore enforce this check with isTRUE

@JanMarvin JanMarvin merged commit 5e813af into main May 13, 2022
@JanMarvin JanMarvin deleted the wb_to_df_cleanup branch October 27, 2022 23:13
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.

None yet

1 participant