openxlsx icon indicating copy to clipboard operation
openxlsx copied to clipboard

Warning in `dataValidation(type = "list")`

Open tentacles-from-outer-space opened this issue 2 years ago • 6 comments

dataValidation(type = "list") generates warning warning because of redundant argument to sprintf:

https://github.com/ycphs/openxlsx/blob/d8c8209a42b7ec58e0066ccba9ea8a748ad77f16/R/WorkbookClass.R#:~:text=data_val%20%3C%2D%20sprintf(%27%3Cx14,showInputMsg%2C%20showErrorMsg%2C%20sqref)

Instead of

data_val <- sprintf('<x14:dataValidation type="list" allowBlank="%s" showInputMessage="%s" showErrorMessage="%s">',
                      allowBlank, showInputMsg, showErrorMsg, sqref)

should be

data_val <- sprintf('<x14:dataValidation type="list" allowBlank="%s" showInputMessage="%s" showErrorMessage="%s">',
                      allowBlank, showInputMsg, showErrorMsg)

Adding reprex (extracted from example(dataValidation) on openxlsx 4.2.5.1):

library(openxlsx)
wb <- createWorkbook()
addWorksheet(wb, "Sheet 1")
addWorksheet(wb, "Sheet 2")

writeDataTable(wb, sheet = 1, x = iris[1:30, ])
writeData(wb, sheet = 2, x = sample(iris$Sepal.Length, 10))

dataValidation(wb, 1, col = 1, rows = 2:31, type = "list", value = "'Sheet 2'!$A$1:$A$10")
#> Warning in sprintf("<x14:dataValidation type=\"list\" allowBlank=\"%s\"
#> showInputMessage=\"%s\" showErrorMessage=\"%s\">", : one argument not used by
#> format '<x14:dataValidation type="list" allowBlank="%s" showInputMessage="%s"
#> showErrorMessage="%s">'

Created on 2022-06-15 by the reprex package (v2.0.1)

wleoncio avatar Jun 15 '22 07:06 wleoncio

@JanMarvin I can confirm the warning message is gone in the current development branch (not sure if you want to be actively tagged, but since you asked if someone could test the changes in the dev branch, I thought you'd want to).

deschen1 avatar Jul 06 '22 08:07 deschen1

Thanks for testing, @deschen1! I understand the repo is basically no longer maintained, but it would be nice if someone would close this issue since it's solved.

wleoncio avatar Jul 13 '22 12:07 wleoncio

Rest assured, this repository is still maintained. The last merge to development was just yesterday. We might not always be the fastest, but not actively developing and not being maintained are different things. People just have different things to do in life and some of us have to work for a living 😉 There will be new releases with bugfixes etc, just not at the moment.

JanMarvin avatar Jul 13 '22 15:07 JanMarvin

not actively developing and not being maintained are different things

You're right, sorry for misspeaking. Great to know there are new releases on the horizon!

wleoncio avatar Jul 14 '22 12:07 wleoncio

Is it possible to define formula1 in dataValidation when the type is list by giving a list of values rather than specifying a sheet range? Like

library(openxlsx) wb <- createWorkbook() addWorksheet(wb, "Sheet 1") addWorksheet(wb, "Sheet 2")

writeDataTable(wb, sheet = 1, x = iris[1:30, ]) writeData(wb, sheet = 2, x = sample(iris$Sepal.Length, 10))

dataValidation(wb, 1, col = 1, rows = 2:31, type = "list", value = "'option1,option2")

When I try to do this, I get an error in the resulting excel file.

IRorpa avatar Sep 23 '22 16:09 IRorpa

This issue is stale because it has been open 365 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Sep 30 '23 01:09 github-actions[bot]

This issue was closed because it has been stalled for 7 days with no activity.

github-actions[bot] avatar Oct 07 '23 01:10 github-actions[bot]