|
15 | 15 |
|
16 | 16 | r['options'](warn=-1) |
17 | 17 |
|
18 | | -required_packages = ["Rcpp", "dfoptim", "bcn"] # list of required R packages |
19 | | - |
20 | | -if all(rpackages.isinstalled(x) for x in required_packages): |
21 | | - check_packages = True # True if packages are already installed |
22 | | -else: |
23 | | - check_packages = False # False if packages are not installed |
24 | | - |
25 | | -if check_packages == False: # Not installed? Then install. |
26 | | - |
27 | | - packages_to_install = [ |
28 | | - x for x in required_packages if not rpackages.isinstalled(x) |
29 | | - ] |
30 | | - |
31 | | - if len(packages_to_install) > 0: |
32 | | - base = importr("base") |
33 | | - utils = importr("utils") |
34 | | - base.options( |
35 | | - repos=base.c( |
36 | | - techtonique="https://techtonique.r-universe.dev", |
37 | | - CRAN="https://cran.rstudio.com/", |
| 18 | +# Install R packages |
| 19 | +commands1_lm = 'base::system.file(package = "bcn")' # check is installed |
| 20 | +commands2_lm = 'base::system.file("bcn_r", package = "bcn")' # check is installed locally |
| 21 | +exec_commands1_lm = subprocess.run(['Rscript', '-e', commands1_lm], capture_output=True, text=True) |
| 22 | +exec_commands2_lm = subprocess.run(['Rscript', '-e', commands2_lm], capture_output=True, text=True) |
| 23 | + |
| 24 | +if (len(exec_commands1_lm.stdout) == 7 and len(exec_commands2_lm.stdout) == 7): # kind of convoluted, but works |
| 25 | + |
| 26 | + required_packages = ["Rcpp", "dfoptim", "bcn"] # list of required R packages |
| 27 | + |
| 28 | + if all(rpackages.isinstalled(x) for x in required_packages): |
| 29 | + check_packages = True # True if packages are already installed |
| 30 | + else: |
| 31 | + check_packages = False # False if packages are not installed |
| 32 | + |
| 33 | + if check_packages == False: # Not installed? Then install. |
| 34 | + |
| 35 | + packages_to_install = [ |
| 36 | + x for x in required_packages if not rpackages.isinstalled(x) |
| 37 | + ] |
| 38 | + |
| 39 | + if len(packages_to_install) > 0: |
| 40 | + base = importr("base") |
| 41 | + utils = importr("utils") |
| 42 | + base.options( |
| 43 | + repos=base.c( |
| 44 | + techtonique="https://techtonique.r-universe.dev", |
| 45 | + CRAN="https://cran.rstudio.com/", |
| 46 | + ) |
38 | 47 | ) |
39 | | - ) |
40 | | - try: |
41 | | - utils.install_packages(StrVector(packages_to_install)) |
42 | | - except Exception as e1: |
43 | 48 | try: |
44 | | - subprocess.run(['mkdir', '-p', 'bcn_r']) |
45 | | - utils.install_packages(StrVector(packages_to_install), lib_loc = StrVector(['bcn_r'])) |
46 | | - except Exception as e2: |
47 | | - subprocess.run(["mkdir", "-p", "bcn_r"], check=True) |
48 | | - command1 = "Rscript -e \"try(utils::install.packages(c('Rcpp', 'dfoptim'), lib='bcn_r', repos='https://cran.rstudio.com', dependencies = TRUE), silent=TRUE)\"" |
49 | | - subprocess.run(command1, shell=True, check=True) |
50 | | - command2 = "Rscript -e \"try(utils::install.packages('bcn', lib='bcn_r', repos='https://techtonique.r-universe.dev', dependencies = TRUE), silent=TRUE)\"" |
51 | | - subprocess.run(command2, shell=True, check=True) |
52 | | - |
53 | | - check_packages = True |
| 49 | + utils.install_packages(StrVector(packages_to_install)) |
| 50 | + except Exception as e1: |
| 51 | + try: |
| 52 | + subprocess.run(['mkdir', '-p', 'bcn_r']) |
| 53 | + utils.install_packages(StrVector(packages_to_install), lib_loc = StrVector(['bcn_r'])) |
| 54 | + except Exception as e2: |
| 55 | + subprocess.run(["mkdir", "-p", "bcn_r"], check=True) |
| 56 | + command1 = "Rscript -e \"try(utils::install.packages(c('Rcpp', 'dfoptim'), lib='bcn_r', repos='https://cran.rstudio.com', dependencies = TRUE), silent=TRUE)\"" |
| 57 | + subprocess.run(command1, shell=True, check=True) |
| 58 | + command2 = "Rscript -e \"try(utils::install.packages('bcn', lib='bcn_r', repos='https://techtonique.r-universe.dev', dependencies = TRUE), silent=TRUE)\"" |
| 59 | + subprocess.run(command2, shell=True, check=True) |
| 60 | + |
| 61 | + check_packages = True |
54 | 62 |
|
55 | 63 | base = importr("base") |
56 | 64 | try: |
|
0 commit comments