0

I am attempting to get some conditional formatting on an created .xlsx file with R and openxlsx. Wrote the below code which has worked in the past but I am now receiving the error below. I cannot tell if this is a me problem or if openxlsx isn't correctly installed.

thanks for the help.

##define conditional formatting rules
   rule1 <- rule("($O1-$T1)/$O1 < -0.1", style = createStyle(fontColour = "red"))
   rule2 <- rule("($O1-$T1)/$O1 >= -0.1 & ($O1-$T1)/$O1 <= -0.15", style = createStyle(fontColour = "orange"))
   rule3 <- rule("($O1-$T1)/$O1 > -0.15", style = createStyle(fontColour = "green"))
   
## Combine the rules using addConditionalFormatting
   addConditionalFormatting(sheet, cols = "H",
                            rows = 1:nrow(data),
                            rules = list(rule1, rule2, rule3))

Error in rule("($O1-$T1)/$O1 < -0.1", style = createStyle(fontColour = "red")) : could not find function "rule"

I expected the above to add the correct formatting to the final file, but the script now stops here.

rhood133
  • 1
  • 1
  • openxlsx is loaded already and has plenty of other functions used before this block, thanks. – rhood133 Feb 28 '23 at 17:38
  • On my computer `??rule` returns no results - so I know none of my installed packages have a function named `rule`. But if the package is installed on your system then `??rule` should find it. And then you can load that package. – Gregor Thomas Feb 28 '23 at 17:51
  • 1
    I think you've got the wrong syntax for specifying mutliple rules - check the examples here: https://rdrr.io/cran/openxlsx/man/conditionalFormatting.html – Paul Stafford Allen Feb 28 '23 at 17:51
  • I don't see any references to a function named `rule` in the `openxlxs` documentation: https://cran.r-project.org/web/packages/openxlsx/openxlsx.pdf – MrFlick Feb 28 '23 at 18:03

0 Answers0