Search code examples
rdplyrsentimentr

dplyr mutate throws "Error: invalid subscript type 'closure'" error


I'm trying to use the sentiment_by in sentimentR with dplyr's mutate

This for example works: content <- mutate(content, word_count = sentiment_by(story)$word_count)

but

This for example works: content.sd <- mutate(content, word_count = sentiment_by(story)$sd)

gives the error Error: invalid subscript type 'closure'

but sentiment_by(content$story[1]) works

Any help would be greatly appreciated.


Solution

  • You can use the following instead

    content <- mutate(content, stdev = sentiment_by(story)[["sd"]])