This article describes how to go from a table...

...to an output that displays a custom message when the sample size is too small.

## Requirements

Please note these steps require a **Displayr **license.

A table with a sample size statistic showing, such as **Column Sample Size** or **Sample Size**.

## Method

1. Select your table.

2. Go to **Properties > GENERAL > Name** and copy the object name.

3. Select** Calculation > Custom Code**.

4. In the **object inspector**, go to **Properties > R CODE**.

5. Paste in the following code and edit the inputs section to what you need. This will make the output transparent if there's enough data and show your custom error message with a white background if not:

###################

### INPUTS

###################

#identify the table to use

mytable = table.sample

#identify the column to use (must be selected in Statistics-Cells)

ss = "Sample Size"

#set the minimum sample size

min.sample = 40

#set the error message

errmsg= "Sample size is too small to show results"

###################

#test if there is any data in the table

hasdata = length(mytable) != 0

#if the table has data test the sample size is big enough

if(hasdata){

hassample = mytable[1,ss] >= min.sample

#if table has multiple columns and sample size is a statistic comment out above and in below

#hassample = mytable[1,1,ss] >= min.sample

} else {

hassample=FALSE

}

##if there's enough sample size have box be transparent (html = "")

##else if there's not enough data show error message using html

html = if (hassample) '' else paste0("<!DOCTYPE html>

<html>

<head>

<style>

body { background-color: white; }

</style>

</head>

<body>",errmsg,"

</body>

</html>")

rhtmlMetro::Box(html, text.as.html = TRUE)

8. Resize the output to cover whatever you wish to disappear.

## See Also

How to Handle Outputs with Small or No Data using R

How to Work with Conditional R Formulas

How to Hide an Output with a Small Sample Size Using an R Error

How to Blank or Cap R Table Cells Based on a Different Statistic Using R

How to Hide Rows or Columns Based on Sample Size Using R