strsplit不一贯工作,字母之间的字符不是空格?

Can*_*ice 2 whitespace r character

问题很简单,但我没有运气修复它.strsplit()是一个相当简单的功能,我很惊讶我和我一样挣扎:

# temp is the problem string. temp is copy / pasted from my R code.
# i am hoping the third character, the space, which i think is the error, remains the error 
temp = "GS PG"

# temp2 is created in stackoverflow, using an actual space
temp2 = "GS PG"

unlist(strsplit(temp, split = " "))
[1] "GS PG"
unlist(strsplit(temp2, split = " "))
[1] "GS" "PG"
Run Code Online (Sandbox Code Playgroud)

.
即使它不能与我一起尝试重现这个例子,这也是我遇到的问题.对于temp,代码不会因为某些奇怪的原因而在空间上拆分变量.任何想法将不胜感激!

最好,

编辑 - 我的例子未能重新创建该问题.作为参考,通过使用rvest从在线搜索代码,我的代码中创建了temp,并且由于某种原因,它必须抓取除正常空间之外的其他角色,我想?我需要按空格分割这些字符串.

ode*_*e2k 5

请尝试以下方法:

unlist(strsplit(temp, "\\s+"))
Run Code Online (Sandbox Code Playgroud)

"\\s+"是一个正则表达式搜索任何类型的空白而不仅仅是标准空间.