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
A table with a sample size statistic shown in Statistics > Cells of the table, such as Column Sample Size or Sample Size.
Method
1. Select your table.
2. Go to General > General > Name and copy the object name in the object inspector .
3. From the toolbar or from the + in the Report tree, select Calculation > Custom Code.
4. Paste in the following code in the R code editor 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)5. Resize the output to cover whatever you wish to disappear.
Next
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
UPCOMING WEBINAR: The Roadmap for Market Researchers in the Age of AI