don't use askYesNo for R < 3.5

This commit is contained in:
Hong Ooi 2019-09-11 12:29:55 +10:00
Родитель e56a077051
Коммит a1b943d16c
3 изменённых файлов: 21 добавлений и 6 удалений

Просмотреть файл

@ -15,11 +15,11 @@ make_AzureR_dir <- function()
AzureR_dir <- AzureR_dir()
if(!dir.exists(AzureR_dir) && interactive())
{
ok <- utils::askYesNo(paste0(
ok <- confirmed(paste0(
"The AzureR packages can save your authentication credentials in the directory:\n\n",
AzureR_dir, "\n\n",
"This saves you having to re-authenticate with Azure in future sessions. Create this directory?"))
if(!isTRUE(ok))
if(!ok)
return(invisible(NULL))
dir.create(AzureR_dir, recursive=TRUE)

Просмотреть файл

@ -256,8 +256,8 @@ delete_azure_token <- function(resource, tenant, app, password=NULL, username=NU
if(confirm && interactive())
{
ok <- utils::askYesNo("Do you really want to delete this Azure Active Directory token?", FALSE)
if(!isTRUE(ok))
ok <- confirmed("Do you really want to delete this Azure Active Directory token?", FALSE)
if(ok)
return(invisible(NULL))
}
file.remove(file.path(AzureR_dir(), hash))
@ -274,8 +274,8 @@ clean_token_directory <- function(confirm=TRUE)
if(confirm && interactive())
{
ok <- utils::askYesNo("Do you really want to delete ALL saved Azure Active Directory tokens?", FALSE)
if(!isTRUE(ok))
ok <- confirmed("Do you really want to delete ALL saved Azure Active Directory tokens?", FALSE)
if(ok)
return(invisible(NULL))
}
toks <- dir(AzureR_dir(), pattern="^[0-9a-f]{32}$", full.names=TRUE)

Просмотреть файл

@ -122,3 +122,18 @@ paste_v2_scopes <- function(scope)
{
paste(scope, collapse=" ")
}
confirmed <- function(msg, default=TRUE)
{
ok <- if(getRversion() < numeric_version("3.5.0"))
{
msg <- paste(msg, if(default) "(Yes/no/cancel)" else "(yes/No/cancel)")
yn <- readline(msg)
if(nchar(yn) == 0)
default
else tolower(substr(yn, 1, 1)) == "y"
}
else utils::askYesNo(msg, default)
isTRUE(ok)
}