From the Tableau and R Integration documentation:
Given that the SCRIPT_*() functions work as table calculations, they
require aggregate measures or Tableau parameters to work properly.
Aggregate measures include MIN(), MAX(), ATTR(), SUM(), MEDIAN(), and
any table calculations or R measures. If you want to use a specific
non-aggregated dimension, it needs to be wrapped in an aggregate
function.
In your case you could do:
SCRIPT_STR(
'output <- .arg1; output', ATTR([comments])
)
ATTR()
is a special Tableau aggregate that does the following:
IF MIN([Dimension]) = MAX([Dimension]) THEN
[Dimension] ELSE * (a special version of Null) END
It’s really useful when building visualizations and you’re not sure of the level of detail of data and what’s being sent
Note: It can be significantly slower than MIN()
or MAX()
in large data sets, so once you get confident your results are accurate then you can switch to one of the other functions for performance.