I am trying to create an hashtag extraction function in R. This function will extract a hashtags from a post, if there are any, else will give a blank. My function is like
hashtag_extract= function(text){
match = str_extract_all(text,"#\\S+")
if (match) {
return match
}else{
return ''}}
String="#letsdoit #Tonewbeginnign world is on a new#route
But my function is not working, showing me tons of errors.like 1st error is
Error: unexpected symbol in:
" if (match) {
return match"
so I want to apply it as
hashatag_extract(string)
and answer should come like
#letsdoit ##Tonewbeginnign #route
And eventually I will use sapply to apply this function on whole column, that's why the If part is important. Please ignore my indentation for R, since its not important for R, but every suggestion will be helpful