Double quotes with List in R

796 views Asked by At

I am trying to add quotes to a list which is output from predict in recommenderlab library. which looks something as below. I am facing challenge to get this into a concatenated string something like

List: 
"Key" 
"value1" "value2" "value3" 
"value4" .............. 

expected:

"value1", "value2", "value3", "value4" .......... 

tried different ways

used:

stri_join_list(v_list, sep = ";", collapse = NULL) 

Edited for more information

library("recommenderlab")

data("MovieLense")

MovieLense100 <- MovieLense[rowCounts(MovieLense) >100,]

MovieLense100

train <- MovieLense100[1:50]

rec <- Recommender(train, method = "UBCF")

rec

pre <- predict(rec, MovieLense100[101:102], n = 10)

as(pre, "list")

when you see the list here it will be in above mentioned format :

$`291`
 [1] "Titanic (1997)"                         "Contact (1997)"                         "Alien (1979)"                          
 [4] "Amadeus (1984)"                         "Godfather, The (1972)"                  "Aliens (1986)"                         
 [7] "Sting, The (1973)"                      "American Werewolf in London, An (1981)" "Schindler's List (1993)"               
[10] "Glory (1989)"                          

I want it to be like :

"Titanic (1997)", "Contact (1997)", "Alien (1979)"  ....

all concatenated as one string, just like above

Thanks but

paste0(shQuote(list1),collapse=",")

above also not what I am looking as this gives me "\", please let me know what can be done

cat(paste0(shQuote(v_list[["bi_Marika77"]]),collapse=";"))

-- This worked . Thanks All

However, I have a small challenge here Want to keep the resultant of the above in dataframe where first column will be userid and second column will be concatenated list. please help!

1

There are 1 answers

4
Fino On

I think you are looking for shQuote()

list1 = as(pre, "list")
paste0(shQuote(list1$`291`),collapse=",")