The first program is a reprex of the minimal App that is necessary to run a script and the second program is a reprex of the minimal script. The app is called AppglyCount1.R and the script is called glyCount1.R. The third program is a reprex of the program that produces the input files. The problem I am having is in glyCount1.R , specifically here:
for(i in 1:length(lc)){
for(j in 1:length(lc[[i]])){
# I have to relsit file_content
file_content <- tryCatch(read.csv( paste(getwd(), "/", lc[[i]][j], sep = ""), header = TRUE, sep = ","), error = function(e) NULL)
#
}
new_path[i] <- paste(getwd(), "/", new_dataFns[i], sep = "")
new_path[i] <- gsub('\\s+', '', new_path[i])
#write.table(file_content, file = new_path[i], append = TRUE, col.names = FALSE)
}
I want to iterate over the list new_path containing the directories with the new files, but the code only produces one directory and the file attached to the directory is called name1. Since I have selected 3 groups of files through inputSelect - the first time I select 4 files, the second time I select 3 files and the third time I select 2 files - I input 3 names through the inputText box. What I intend to do is producing path/name1, path/name2 and path/name3. That is why I write the new directory code in the loop. However, the loop only produces path/name1.
The code reads the files in the inner loop because the input is a list of lists.
Once I have path/name1, path/name2, path/name3, I want to write the first 4 files to path/name1, the second 3 files to path/name2, and the third 3 files to path/name3. Could you please help me to get path/name1, path/name2 and path/name3?
Thanks
PROGRAM 1 - AppglyCount1.R
library(shiny)
library(shinyjs)
#>
#> Attaching package: 'shinyjs'
#> The following object is masked from 'package:shiny':
#>
#> runExample
#> The following objects are masked from 'package:methods':
#>
#> removeClass, show
ui <- fluidPage(
selectInput("combinefiles", label = h5(strong("Do you wish to combine any data files, and compare the combined data sets? (Y/N) ")),
choices = c("", "Y", "N"),selected = NULL),
verbatimTextOutput("combiningFiles"),
verbatimTextOutput("combineChosen"),
verbatimTextOutput("filesToCombine"),
useShinyjs(),
conditionalPanel(
condition = "output.toCombine > '0'",
selectInput(inputId = "select",label = h5(strong("Please select from the list")), choices = c(Chose = "", list.files("~/Development/glycoPipeApp")), multiple = TRUE, selectize = TRUE)
),
conditionalPanel(
condition = "output.displayAddButton > '0'",
actionButton('add','Add')
),
verbatimTextOutput("samelist"),
conditionalPanel(
condition = "output.displayAddButton == 1",
actionButton("sBtn", "Press the save button to end")
),
conditionalPanel(
condition = "output.displayTheSaveButton > '0'",
textInput("textbox", h5(strong("Please enter name/s to designate combined set/s separated by comma")))),
strong(verbatimTextOutput("list")),
verbatimTextOutput("caption")
)
#selections = NULL,
glycoPipe <- function(response = NULL, fOfData = NULL, combineResult = NULL, listContents = NULL, vals = NULL){
enteredValue = NULL
nameList = NULL
answer = NULL
fileChoice = NULL
combination = NULL
combinations = NULL
comb = NULL
nameListSize = NULL
if(!is.null(response)){
answer = response
}
if(!is.null(fOfData)){
fileChoice = fOfData
# print(fileChoice)
}
if(!is.null(combineResult)){
combination = combineResult
#print(combination)
}
# if(!is.null(selections)){
# combinations = selections
# #print(combinations)
# }
if(!is.null(listContents)){
enteredValue = listContents
}
if(!is.null(vals)){
nameList <- vals
}
choseDataFiles <- glyCount(answer, fileChoice, combination)[[1]]
combine <- glyCount(answer, fileChoice, combination)[[2]]
fileLength <- glyCount(answer, fileChoice, combination, enteredValue, nameList)[[3]]
if(!is.null(choseDataFiles)){
choseDataFiles = choseDataFiles
}
if(!is.null(combine)){
comb = combine
}
if(!is.null(fileLength)){
nameListSize <- fileLength
}
list(choseDataFiles = choseDataFiles, comb = comb, nameListSize = nameListSize)
}
server <- function(input, output, session){
listContents = NULL
source("Utilities/utilities.R")
source("glycoPipeFunctions/glycoPipe_fcns.R")
source("glyCount1.R")
output$toCombine <- reactive({
req(input$combinefiles)
return(length(input$combinefiles))
})
outputOptions(output, "toCombine", suspendWhenHidden = FALSE)
output$displayAddButton <- reactive({
req(input$combinefiles)
return(length(input$combinefiles))
})
outputOptions(output, "displayAddButton", suspendWhenHidden = FALSE)
output$displayTheSaveButton <- reactive({
req(input$sBtn)
return(input$sBtn)
})
outputOptions(output, "displayTheSaveButton", suspendWhenHidden = FALSE)
myValues <- reactiveValues()
observe({
if(input$add > 0){
myValues$dList <- c(isolate(myValues$dList), isolate(list(input$select)))
}
})
# #unlist(input$filescombine)
output$samelist<-renderPrint({
#listContents <- list()
listContents <- append(listContents, myValues$dList)
print(listContents)
if(input$sBtn > 0){
numberOfSelectedSets <- glycoPipe(response = NULL, fOfData = NULL, combineResult = NULL , listContents)
paste("Please enter", numberOfSelectedSets$nameListSize, "names to designate your", numberOfSelectedSets$nameListSize, "sets")
}
})
VALUES <- list()
observe({
isolate({
req(input$textbox)
VALUES <- input$textbox
VALUES <- append(VALUES, list(input$textbox))
updateTextInput(session, inputId = "textbox", value = VALUES)
})
})
output$caption <- renderPrint({
vals <- list()
vals <- append(vals, input$textbox)
if(input$sBtn > 0){
result <- glycoPipe(response = NULL, fOfData = NULL, combineResult = NULL, listContents, vals)
#unlist(input$filescombine)
}
})
session$allowReconnect(TRUE)
}
shinyApp(ui = ui, server = server)
Created on 2018-09-01 by the reprex package (v0.2.0).
SECOND PROGRAM - glyCount1.R
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
glyCount <- function(answer = NULL, fileChoice = NULL, combination = NULL, enteredValue = NULL, nameList = NULL) {
#The purpose of the program is to read the files in lc: first list1, second list2 , third list3 and merge the files in each lists separately
#to make 3 sepate files. The first file will contain the contents of list1, the second file will contents the contents of list2 and the third file
#will contain the contents of list three.
#I am saving the files - 20 lines of each - in the working directory.install
# Length of list
lc <- enteredValue
elementname <- nameList
choseDataFiles = TRUE
fileLength <- length(lc)
# # These are the names that will be given to the 3 resulting files
first_path <- NULL
new_path <- NULL
#add the file names to the path and read and merge the contents of each list in the list of lists
new_dataFns = NULL
first_path <- NULL
new_path <- NULL
new_dataFns <- unlist(strsplit(as.character(elementname), ","))
file_content <- NULL
for(i in 1:length(lc)){
for(j in 1:length(lc[[i]])){
# I have to relsit file_content
file_content <- tryCatch(read.csv( paste(getwd(), "/", lc[[i]][j], sep = ""), header = TRUE, sep = ","), error = function(e) NULL)
#
}
new_path[i] <- paste(getwd(), "/", new_dataFns[i], sep = "")
new_path[i] <- gsub('\\s+', '', new_path[i])
#write.table(file_content, file = new_path[i], append = TRUE, col.names = FALSE)
}
list(choseDataFiles = choseDataFiles,
combine = combine, fileLength = fileLength)
}
Created on 2018-09-01 by the [reprex package](http://reprex.t
PROGRAM 3 - reprex to produce files
library(magrittr)
library(reprex)
JF_160426_Dep2Plas_tryp_Gpep_SIDtargPSM<- NULL
JF_160426_Dep2Plas_tryp_Gpep_SIDtargPSM %>% # table that should become a file
head(5) %>% # 5 lines might be plenty?
dput()
#> NULL
0
#> [1] 0
JF_160426_Dep2Plas_tryp_Gpep_SIDtargPSM <-
# Everything below here is the output from above. I used
# fake data for this.
structure(list(
confidence = c("High", "High", "High", "High", "High", "High", "Medium", "High", "High", "High", "High", "High", "High", "High", "High", "Medium", "High", "High", "Medium","High"
),
deltaScore = c("0.1667", "0.5789", "1", "0.56", "0.52", "1", "0.56", "0.5882", "1", "0.52", "1", "0.56", "0.5", "0.2857", "0.5556", "0.55", "0", "0.2857", "0.5789", "0.5"
),
PSM_ambiguity = c("Unambiguous", "Unambiguous", "Unambiguous", "Unambiguous", "Unambiguous", "Unambiguous", "Unambiguous", "Unambiguous", "Unambiguous", "Unambiguous", "Unambiguous", "Unambiguous", "Unambiguous", "Unambiguous", "Unambiguous", "Unambiguous", "Ambiguous", "Unambiguous", "Unambiguous", "Medium"
),
Annotated_Sequence = c("InHcR", "InHcR", "InHcR", "InHcR", "InHcR", "InHcR", "InHcR", "EnGTVSR", "InHcR", "InHcR", "InHcR", "InHcR", "InHcR", "InHcR", "InHcR", "InHcR", "InHcR", "InHcR", "InHcR", "InHcR"
),
Modifications = c("N2(HexNAc); C4(Carbamidomethyl)", "N2(HexNAc); C4(Carbamidomethyl)", "N2(HexNAc); C4(Carbamidomethyl)", "N2(HexNAc); C4(Carbamidomethyl)", "N2(HexNAc); C4(Carbamidomethyl)","N2(HexNAc) C4(Carbamidomethyl)", "N2(HexNAc); C4(Carbamidomethyl)", "N2(HexNAc); C4(Carbamidomethyl)", "N2(HexNAc); C4(Carbamidomethyl)", "N2(HexNAc); C4(Carbamidomethyl)", "N2(HexNAc); C4(Carbamidomethyl)", "N2(HexNAc); C4(Carbamidomethyl)", "N2(HexNAc); C4(Carbamidomethyl)", "N2(HexNAc); C4(Carbamidomethyl)", "N2(HexNAc); C4(Carbamidomethyl)", "N2(HexNAc); C4(Carbamidomethyl)", "N2(HexNAc); C4(Carbamidomethyl)","N2(HexNAc); C4(Carbamidomethyl", "N2(HexNAc); C4(Carbamidomethyl", "N2(HexNAc); C4(Carbamidomethyl)"
)
), .Names = c("confidence", "deltaScore","PMS_Ambiguity", "Annotated_Sequence", "Modifications"), row.names = c(
NA,
-20L
), class = c("tbl_df", "tbl", "data.frame"))
write.csv(JF_160426_Dep2Plas_tryp_Gpep_SIDtargPSM, "F_160426_Dep2Plas_tryp_Gpep_SIDtargPSM.csv")
rm(JF_160426_Dep2Plas_tryp_Gpep_SIDtargPSM)
Created on 2018-09-01 by the reprex package (v0.2.0).