Demo entry 2521990

R code

   

Submitted by anonymous on Aug 26, 2015 at 18:29
Language: S. Code size: 1.9 kB.

    idxGroup2 <- c(idxGroup, nrow(dt))
    lengthGroup <- diff(idxGroup2)
    for (i in 1:length(idxGroup)) {
        typeGroup <- dt$type.scale[idxGroup[i]]
        nameGroupSrc <- dt$name[idxGroup[i]]
        nameGroup <- str_replace_all(nameGroupSrc, fixed(" "), "_")
        fname <- paste(typeGroup, nameGroup, sep = "_")
        sink(paste(fname, ".txt", sep = ""))
        dt.Group <- dt[(idxGroup[i] + 1):(idxGroup[i] + lengthGroup[i] - 1), ]
        idxQ <- which(dt.Group$class == "Q")
        idxQ2 <- c(idxQ, nrow(dt.Group))
        lengthQ <- diff(idxQ2)
        lengthQ[length(lengthQ)] <- lengthQ[length(lengthQ)] + 1
        for (j in 1:length(idxQ)) {
            qName <- str_trim(dt.Group$name[idxQ[j]])
            rtCheck <- check.rtTable(qName, nameGroupSrc)
            if (str_trim(dt.Group$text[idxQ[j]]) %in% tiSource) {
                titmp <- str_trim(dt.Group$text[idxQ[j]])
                ti <- substring(titmp, 9)
                ti <- substr(ti, 1, nchar(ti) - 9)
                tiSourceTxt <- paste("\n\n\n", "==== ", ti, " ====", sep = "")
                cat(tiSourceTxt)
            } else {
                qCodeTxt <- paste("\n\n\n", ">  ", qCodeBegin, dt.Group$name[idxQ[j]], qCodeEnd, sep = "")
                cat(paste(qCodeTxt, dt.Group$text[idxQ[j]], "\n", sep = "   "))
            }
            if (lengthQ[j] >= 2) {
                rtTab <- c("\n\n^Answer ^Rating |")
                for (k in 1:(lengthQ[j] - 1)) {
                    aIdx <- idxQ[j] + k
                    rtTab <- paste(rtTab, "\n^", dt.Group$name[aIdx], " |  |", sep = "")
                    aCodeTxt <- paste("  * ", dt.Group$name[aIdx], ": ", sep = "")
                    cat(paste("\n", aCodeTxt, dt.Group$text[aIdx], sep = ""))
                }
                if (rtCheck == 0) cat(rtTab)
            }
        }
    sink()
    }

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).