File size: 2,581 Bytes
d2a8669
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#' Install aif360 and its dependencies
#'
#' @inheritParams reticulate::conda_list
#'
#' @param method Installation method. By default, "auto" automatically finds a
#'   method that will work in the local environment. Change the default to force
#'   a specific installation method. Note that the "virtualenv" method is not
#'   available on Windows. Note also
#'   that since this command runs without privilege the "system" method is
#'   available only on Windows.
#'
#' @param version AIF360 version to install. Specify "default" to install
#'  the latest release.
#'
#' @param envname Name of Python environment to install within
#'
#' @param extra_packages Additional Python packages to install.
#'
#' @param restart_session Restart R session after installing (note this will
#'   only occur within RStudio).
#'
#' @param conda_python_version the python version installed in the created conda
#'   environment. Python 3.6 is installed by default.
#'
#' @param ... other arguments passed to [reticulate::conda_install()] or
#'   [reticulate::virtualenv_install()].
#'
#'
#' @export
install_aif360 <- function(method = c("auto", "virtualenv", "conda"),
                               conda = "auto",
                               version = "default",
                               envname = NULL,
                               extra_packages = NULL,
                               restart_session = TRUE,
                               conda_python_version = "3.7",
                               ...) {

  method <- match.arg(method)

  reticulate::py_install(
    packages       = c("aif360", "numba", "BlackBoxAuditing", "tensorflow>=1.13.1,<2", "pandas", 
                       "fairlearn==0.4.6", "protobuf==3.20.1"),
    envname        = envname,
    method         = method,
    conda          = conda,
    python_version = conda_python_version,
    pip            = TRUE,
    ...
  )

  cat("\nInstallation complete.\n\n")

  if (restart_session && rstudioapi::hasFun("restartSession"))
    rstudioapi::restartSession()

  invisible(NULL)
}

#' Read CSV file
#' @param inp data file
#' @noRd
#' @importFrom utils read.csv
#'
input_data <- function(inp){
  read.csv(inp)
}
#' create a list
#' @param i input for function
#' @noRd
#'
list_fn <- function(i){
  list(i)
}
#' create a list of list
#' @param i input for function
#' @noRd
#'
list_of_list <- function(i){
  list(list(i))
}
#' Create dictionary
#' @param values input
#' @noRd
#' @importFrom reticulate py_dict
#'
dict_fn <- function(values){
  c(py_dict(c(values[[1]]),c(values[[2]]), convert = FALSE))
}