Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass each row as an argument to R script from Tableau calculated field

I am trying to do sentiment analysis on a table that I have.

I want each row of string data to be passed to the R script, but the problem is that Tableau is accepting only aggregate data as params for:

SCRIPT_STR(
  'output <- .arg1; output', [comments]
)

This gives me an error message:

# All fields must be aggregate or constant.
like image 960
user2626445 Avatar asked Dec 24 '22 17:12

user2626445


2 Answers

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.

like image 193
Steven Beaupré Avatar answered Feb 13 '23 04:02

Steven Beaupré


Try MIN([comments]) and make sure you have appropriate dimensions on your viz to partition the data fine enough to get a single comment for each combination of dimensions.

like image 27
Alex Blakemore Avatar answered Feb 13 '23 03:02

Alex Blakemore