jpcaveiro / rmdmoodle

rmdmoodle
MIT License
0 stars 0 forks source link

variants = function(nrep, enredo, alineas) { #1

Closed jpcaveiro closed 4 months ago

jpcaveiro commented 1 year ago

# -----------
# HERE
# -----------
variants = function(nrep, enredo, alineas) {

  # TODO: melhorar
  # tempfile(fileext = ".Rmd")
  temp_filename = 'LIXO.Rmd'
  filecon <- file(temp_filename, 'wt') 

  # Build a variant
  writeLines(text = "## Variante `r VAR`\n\n", 
             con = filecon)

  #Lê o enredo
  extxt = readLines(paste0(EXDIR,enredo))

  #Escreve o enredo
  writeLines(text = extxt, con = filecon)

  # Lê e escreve as alíneas
  if (length(alineas)==1) {

    # alína única não tem numeração "(a)"

    extxt = readLines(paste0(EXDIR,alineas[1])) #uma única

    #writeLines(text=paste0("\n\n**(", letters[l], ")**\n\n"), con=filecon)

    writeLines(text = extxt, con = filecon)

  } else {

    # várias alíneas 

    l = 1
    for( expath in alineas) {
        extxt = readLines(paste0(EXDIR,expath))

        writeLines(text=paste0("\n\n**(", letters[l], ")**\n\n"), con=filecon)
        writeLines(text = extxt, con = filecon)

        l = l+1

    }
  }

  # Build a variant
  writeLines(text = "\n\n### feedback\n\n", 
             con = filecon)

  flush(filecon)
  close(filecon)

  for(VAR in 1:nrep) {
    VAR <<- VAR
    assertthat::assert_that(VAR <= COUNT)
    cat(knitr::knit_child(temp_filename, quiet = TRUE));
  }

  # Now let's delete it.
  # unlink(txtPath)
} 

#  <https://bookdown.org/yihui/rmarkdown-cookbook/child-document.html>