@@ -161,42 +161,32 @@ nwinit <- reactive({
161161 } else {
162162 filepath <- input $ rawdatafile [1 ,4 ]
163163 filename <- input $ rawdatafile [1 ,1 ]
164- }
165- if (input $ filetype == 1 ){
166- loadfile <- ' '
167- if (! is.null(input $ rawdatafile )){
168- nw_var <- tryCatch({
169- obj <- load(paste(filepath ))
170- }, error = function (err ){
171- return (" Chosen file is not an R object" )
172- }, finally = NULL
173- )
174- try(nw_var <- get(obj ))
175- }
176- } else if (input $ filetype == 2 ){
177- if (! is.null(input $ rawdatafile )){
164+ fileext <- substr(filename ,nchar(filename )- 3 ,nchar(filename ))
165+
166+ if (input $ filetype == 1 ){
167+ if (fileext %in% c(" .rds" , " .Rds" , " .RDs" , " .RDS" )){
168+ nw_var <- readRDS(paste(filepath ))
169+ } else {
170+ return (" Upload a .rds file" )
171+ }
172+
173+ } else if (input $ filetype == 2 ){
178174 nw_var <- " Upload a .net file"
179- if (substr(filename ,nchar(filename )- 3 ,nchar(filename ))== " .net" |
180- substr(filename ,nchar(filename )- 3 ,nchar(filename ))== " .NET" ){
175+ if (fileext %in% c(" .net" , " .NET" )){
181176 nw_var <- read.paj(paste(filepath ))
182177 }
183- }
184- } else if (input $ filetype == 3 ){
185- if (! is.null(input $ rawdatafile )){
178+ } else if (input $ filetype == 3 ){
186179 nw_var <- " Upload a .paj file"
187- if (substr(filename ,nchar(filename )- 3 ,nchar(filename ))== " .paj" |
188- substr(filename ,nchar(filename )- 3 ,nchar(filename ))== " .PAJ" ){
180+ if (fileext %in% c(" .paj" ," .PAJ" )){
189181 nws <- read.paj(paste(filepath ))
190182 if (! is.null(pajnws())){
191183 nw_var <- nws $ networks [[as.numeric(input $ choosepajnw )]]
192184 }
193185 }
194- }
195- } else if (input $ filetype == 4 ){
196- loadfile <- ' '
197- if (! is.null(input $ rawdatafile )){
186+
187+ } else if (input $ filetype == 4 ){
198188 nw_var <- " Input the specified type of matrix"
199- if (substr( filename ,nchar( filename ) - 3 ,nchar( filename )) == " .csv" ){
189+ if (fileext %in% c( " .csv" , " .CSV " ) ){
200190 header <- TRUE
201191 row_names <- 1
202192 if (input $ matrixtype == " edgelist" ){
@@ -210,24 +200,24 @@ nwinit <- reactive({
210200 ignore.eval = FALSE , names.eval = ' edgevalue' )
211201 })
212202
213- }
214- try({
215- newmx <- load(paste(filepath ))
216- nw_var <- network(get(newmx ),
203+ } else if (fileext %in% c(" .rds" , " .Rds" , " .RDs" , " .RDS" )){
204+ newmx <- readRDS(paste(filepath ))
205+ nw_var <- network(newmx ,
217206 directed = input $ dir , loops = input $ loops ,
218207 multiple = input $ multiple , bipartite = input $ bipartite ,
219208 matrix.type = input $ matrixtype ,
220209 ignore.eval = FALSE , names.eval = ' edgevalue' )
221- })
222- }
210+
211+ }
223212
224- } else if (input $ filetype == 5 ){
225- if (input $ samplenet == " None" ){
226- nw_var <- NULL
227- } else {
228- nw_var <- eval(parse(text = input $ samplenet ))
229- if (! is.element(' bipartite' ,names(nw_var $ gal ))){
230- set.network.attribute(nw_var ,' bipartite' ,FALSE )
213+ } else if (input $ filetype == 5 ){
214+ if (input $ samplenet == " None" ){
215+ nw_var <- NULL
216+ } else {
217+ nw_var <- eval(parse(text = input $ samplenet ))
218+ if (! is.element(' bipartite' ,names(nw_var $ gal ))){
219+ set.network.attribute(nw_var ,' bipartite' ,FALSE )
220+ }
231221 }
232222 }
233223 }
0 commit comments