22# ' @title searches for opal login object in the environment
33# ' @description This is an internal function required by a client function
44# ' @details if the user does not set the argument 'datasources', this function
5- # ' is called to searches for opal login objects in the environment. If more than one
6- # ' login object is found a prompt asks the user to choose one and if none is found
7- # ' the process stops.
5+ # ' is called to searches for opal login objects in the environment.
6+ # ' If only one opal object is found, it automatically becomes the default selection.
7+ # ' If more than one is found but one is called 'default.opals' then that is selected.
8+ # ' If more than one is found with none is called 'default.opals' the user is
9+ # ' told that they can either specify a particular Opal using the 'datasources=' argument
10+ # ' that exists in every relevant datashield client-side function or else they
11+ # ' can use the 'ds.setDefaultOpals()' function to create a copy of a selected Opal objects
12+ # ' which is called 'default.opals' and is then selected by default in future calls to findLoginObjects.
13+ # ' If the default Opal object needs to be changed then 'ds.setDefaultOpals()' can be run again.
14+ # ' A previous version of 'findLoginObjects()' asked the user to specify which Opal to choose
15+ # ' if no default could be identified, but that did not work in all versions of R and so was removed.
816# ' @keywords internal
917# ' @return returns a list of opal login objects or stops the process
10- # ' @author Gaye, A .
18+ # ' @author Amadou Gaye, Paul Burton (updated 15/10/18). THIS IS VERSION TO USE 8/2/19 .
1119# '
1220findLoginObjects <- function (){
1321
1422 findLogin <- getOpals()
23+
24+ if (findLogin $ flag == 0 ){
25+ stop(" Are you logged in to any server? Please provide a valid opal login object! " , call. = FALSE )
26+ }
27+
1528 if (findLogin $ flag == 1 ){
1629 datasources <- findLogin $ opals
17- return (datasources )
18- }else {
19- if (findLogin $ flag == 0 ){
20- stop(" Are you logged in to any server? Please provide a valid opal login object! " , call. = FALSE )
21- }else {
22- message(paste0(" More than one list of opal login object were found: '" , paste(findLogin $ opals ,collapse = " ', '" ), " '!" ))
23- userInput <- readline(" Please enter the name of the login object you want to use: " )
24- datasources <- eval(parse(text = userInput ))
25- if (class(datasources [[1 ]]) == ' opal' ){
26- return (datasources )
27- }else {
28- stop(" End of process: you failed to enter a valid login object" , call. = FALSE )
29- }
30- }
30+ return (datasources )
3131 }
3232
33- }
33+ if (findLogin $ flag > 1 ) {
34+ for (j in 1 : findLogin $ flag ){
35+ if (findLogin $ opals [[j ]]== " default.opals" ){
36+ datasources <- eval(parse(text = findLogin $ opals [[j ]]),envir = 0 )
37+ return (datasources )
38+ }
39+ }
40+ message(paste0(" More than one list of opal login objects was found with no default specified:\n '" , paste(findLogin $ opals.list ,collapse = " ', '" ), " '!!" ))
41+ stop(" \n\n Please specify a default Opal object using the following call syntax:\n ds.setDefaultOpals(opal.name='name of opal in inverted commas')\n\n " ,call. = FALSE )
42+ }
43+
44+ }
45+ # findLoginObjects
0 commit comments