在 R 中拆分文本字符串

Split Text String in R

我在 R 中有一个包含超过 5000 个元素的大列表。元素的形式为:

$`/home/ricardo/MultiClass/data//Execucao_PUBLICACAO_DECISAO_INTERLOCUTORIA_DETERMINACAO_DE_PAGAMENTO/1117.txt.V1 

[1] DATA DE DISPONIBILIZACAO DA PUBLICACAO PELA FONTE OFICIAL: 16/11/2016 Pag 4279 Decisao Processo N RTOrd-0122200-90.2006.5.15.0087  <truncated>`

我想将其转换为两列 dataframe 其中:

c1       
The contents between $ and [1]

c2    
rest of the text

我该如何拆分?重要的是要注意 $[1] 之间的字符串数量可以改变,字符串 $[ e ] 可以出现在文本的其余部分。

提前致谢, 里卡多

library(stringr)

string <- '$/home/ricardo/MultiClass/data//Execucao_PUBLICACAO_DECISAO_INTERLOCUTORIA_DETERMINACAO_DE_PAGAMENTO/1117.txt.V1 [1] DATA DE DISPONIBILIZACAO DA PUBLICACAO PELA FONTE OFICIAL: 16/11/2016 Pag 4279 Decisao Processo N RTOrd-0122200-90.2006.5.15.0087'

c1 <- str_match(string = string, pattern = "^\$(.*) \[1\] (.*)")[,2]
c2 <- str_match(string = string, pattern = "^\$(.*) \[1\] (.*)")[,3]

$ ... 文本是列表元素的名称,[1] ... 是该元素的值。您可以提取这些(或者更好的是,在读取数据时正确分配它们)。

a <- list(`this is the name` = "data stored in that variable")

a
#> $`this is the name`
#> [1] "data stored in that variable"

names(a)
#> [1] "this is the name"

as.character(a)
#> [1] "data stored in that variable"