-1

I have a Flextable df and the following condition:

df = setFlexTableBackgroundColors(df, i = 1, j = 5:15,
colors = ifelse(test$object == 0,"white"))

However it gives me the following error message:

Error in ifelse(test$object == 0, "white") :
argument "no" is missing, with no default"

Apparently the package wants something like this: ifelse(test$object == 0, "white", "black"), because then the condition is working.

However I am using this condition on different rows that have different colors (j = 5:15) and I don't want them to turn "black" if the condition is not fulfilled.

Does someone have any hints how I can solve this problem?

AustinWBryan
  • 3,249
  • 3
  • 24
  • 42
Friday
  • 11
  • 2
  • This is not related to that package. You simply haven't understood how `ifelse` works. There must be an "else" value passed to it. Pass the current colors as the "else" value. – Roland Jan 02 '16 at 17:51
  • I understand how the ifelse future works. I am looking for something like, "Iflese( test==0 , white , if not do nothing and remain the same color )" that works with this Package. – Friday Jan 06 '16 at 10:11

1 Answers1

0

You should provide the function with the default parameter it expects. In this particular case, you can do:

df = setFlexTableBackgroundColors(df, i = 1, j = 5:15,
  colors = ifelse(test$object == 0,"white","gray"))

In a more general case, the default value can be obtained with formals():

defaultColors = formals(setFlexTableBackgroundColors)$colors
df = setFlexTableBackgroundColors(df, i = 1, j = 5:15,
  colors = ifelse(test$object == 0,"white",defaultColors))

For instance:

ff <- function(x, y=5, z=7) {}
formals(ff)$y     # Returns 5
mountrix
  • 1,126
  • 15
  • 32
  • 1
    This is a good idea. Getting the format of the specific cell. However it does not work. I guess it is a feature that does not work with the peculiarities of the packe. I don't know if you have worked with the Package, but the command "format" needs to access a Flextable(x,i=5,j=5,colors=...). But thank you for the idea. I will work in this direction. – Friday Jan 06 '16 at 10:06