1

I've added asterisks and a new line break to the sampleList elements in order to create a bulleted list format:


sampleList <- list(1, 2, 3)

# Create bulleted list
createPoints = function(list) {
  # Pre-allocate list
  setList <- vector(mode = "list", length = length(list))

  # Add elements to each line
  for (i in seq_along(list)) {
    line = sprintf("* %s  \n", list[[i]])
    setList[[i]] <- line
  }
  
  return(setList)
}

finalList = createPoints(sampleList)

Output:

[[1]]
[1] "* 1  \n"

[[2]]
[1] "* 2  \n"

[[3]]
[1] "* 3  \n"

How do I print the individual elements in a bulleted sublist?

This does not work:

  • Bullet 1
    • r finalList

My output comes with extra commas and no bullets for the sublists:

  • Bullet 1

    • 1

    , * 2

    , * 3

I would like it to look like this:

  • Bullet 1
    • 1
    • 2
    • 3
SRL
  • 145
  • 9

1 Answers1

1

Unlist your finalList object and collapse all elements together to avoid commas

sampleList <- list(1, 2, 3)

# Create bulleted list
createPoints = function(list) {
  # Pre-allocate list
  setList <- vector(mode = "list", length = length(list))

  # Add elements to each line
  for (i in seq_along(list)) {
    line = sprintf("* %s  \n", list[[i]])
    setList[[i]] <- line
  }
  
  return(setList)
}

finalList = unlist(createPoints(sampleList))

r paste(finalList, collapse = " ")

Johan Rosa
  • 2,797
  • 10
  • 18