Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/180.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何从字符串中删除换行符?_R_Twitter_Str Replace - Fatal编程技术网

R 如何从字符串中删除换行符?

R 如何从字符串中删除换行符?,r,twitter,str-replace,R,Twitter,Str Replace,我正在使用R中的Twitter API提取推文。 我一直在使用write.csv2命令将结果保存到csv in r中,这很好,但存在一个问题,即tweet文本中的字符返回导致电子表格中一条tweet的多行 我试过使用stru-replace-all,但它似乎对我不起作用,我也找不到任何原因 这是我的密码 searchTags = c("Galwaybikeshare", "Corkbikeshare", "dublinbikes", "BelfastBikes", "SantanderCycle

我正在使用R中的Twitter API提取推文。 我一直在使用write.csv2命令将结果保存到csv in r中,这很好,但存在一个问题,即tweet文本中的字符返回导致电子表格中一条tweet的多行

我试过使用stru-replace-all,但它似乎对我不起作用,我也找不到任何原因

这是我的密码

searchTags = c("Galwaybikeshare", "Corkbikeshare", "dublinbikes", "BelfastBikes", "SantanderCycles", "CitiBikeNYC", "obike", "Hubway", "bicing")

additionalParams = c("-rt -http")

searchString <- paste((paste(searchTags[1:9], collapse = " OR ")), additionalParams, collapse = "")

tweets_list <- searchTwitter(searchString, n=20, lang = "en", resultType = 'recent')

str_replace_all(tweets_list, "[\r\n]" , "")

tweets.df <- twListToDF(tweets_list)

todayDate <- Sys.Date()

tweetArchive <- paste("BikeShareTweets ", todayDate, ".csv", sep ="")

write.csv2(tweets.df, file = tweetArchive)

为什么我的str\u replace\u all没有从文本中删除\n?

stringr::str\u replace\u all
有效,您只是忽略了结果。要解决此问题,请执行以下操作:

tweets_list = str_replace_all(tweets_list, "[\r\n]" , "")

stringr::str\u remove\u all
也可以为您执行此操作

tweets_list = str_remove_all(tweets_list, "[\r\n]")
tweets_list = str_remove_all(tweets_list, "[\r\n]")