Skip to content

Commit

Permalink
align with R version 0.6.1 -- import bcn from local folder Pt.3
Browse files Browse the repository at this point in the history
  • Loading branch information
thierrymoudiki committed Jan 25, 2024
1 parent a54eebc commit 667caa5
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 68 deletions.
76 changes: 42 additions & 34 deletions BCN/BCNClassifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,50 @@

r['options'](warn=-1)

required_packages = ["Rcpp", "dfoptim", "bcn"] # list of required R packages

if all(rpackages.isinstalled(x) for x in required_packages):
check_packages = True # True if packages are already installed
else:
check_packages = False # False if packages are not installed

if check_packages == False: # Not installed? Then install.

packages_to_install = [
x for x in required_packages if not rpackages.isinstalled(x)
]

if len(packages_to_install) > 0:
base = importr("base")
utils = importr("utils")
base.options(
repos=base.c(
techtonique="https://techtonique.r-universe.dev",
CRAN="https://cran.rstudio.com/",
# Install R packages
commands1_lm = 'base::system.file(package = "bcn")' # check is installed
commands2_lm = 'base::system.file("bcn_r", package = "bcn")' # check is installed locally
exec_commands1_lm = subprocess.run(['Rscript', '-e', commands1_lm], capture_output=True, text=True)
exec_commands2_lm = subprocess.run(['Rscript', '-e', commands2_lm], capture_output=True, text=True)

if (len(exec_commands1_lm.stdout) == 7 and len(exec_commands2_lm.stdout) == 7): # kind of convoluted, but works

required_packages = ["Rcpp", "dfoptim", "bcn"] # list of required R packages

if all(rpackages.isinstalled(x) for x in required_packages):
check_packages = True # True if packages are already installed
else:
check_packages = False # False if packages are not installed

if check_packages == False: # Not installed? Then install.

packages_to_install = [
x for x in required_packages if not rpackages.isinstalled(x)
]

if len(packages_to_install) > 0:
base = importr("base")
utils = importr("utils")
base.options(
repos=base.c(
techtonique="https://techtonique.r-universe.dev",
CRAN="https://cran.rstudio.com/",
)
)
)
try:
utils.install_packages(StrVector(packages_to_install))
except Exception as e1:
try:
subprocess.run(['mkdir', '-p', 'bcn_r'])
utils.install_packages(StrVector(packages_to_install), lib_loc = StrVector(['bcn_r']))
except Exception as e2:
subprocess.run(["mkdir", "-p", "bcn_r"], check=True)
command1 = "Rscript -e \"try(utils::install.packages(c('Rcpp', 'dfoptim'), lib='bcn_r', repos='https://cran.rstudio.com', dependencies = TRUE), silent=TRUE)\""
subprocess.run(command1, shell=True, check=True)
command2 = "Rscript -e \"try(utils::install.packages('bcn', lib='bcn_r', repos='https://techtonique.r-universe.dev', dependencies = TRUE), silent=TRUE)\""
subprocess.run(command2, shell=True, check=True)

check_packages = True
utils.install_packages(StrVector(packages_to_install))
except Exception as e1:
try:
subprocess.run(['mkdir', '-p', 'bcn_r'])
utils.install_packages(StrVector(packages_to_install), lib_loc = StrVector(['bcn_r']))
except Exception as e2:
subprocess.run(["mkdir", "-p", "bcn_r"], check=True)
command1 = "Rscript -e \"try(utils::install.packages(c('Rcpp', 'dfoptim'), lib='bcn_r', repos='https://cran.rstudio.com', dependencies = TRUE), silent=TRUE)\""
subprocess.run(command1, shell=True, check=True)
command2 = "Rscript -e \"try(utils::install.packages('bcn', lib='bcn_r', repos='https://techtonique.r-universe.dev', dependencies = TRUE), silent=TRUE)\""
subprocess.run(command2, shell=True, check=True)

check_packages = True

base = importr("base")
try:
Expand Down
76 changes: 42 additions & 34 deletions BCN/BCNRegressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,50 @@

r['options'](warn=-1)

required_packages = ["Rcpp", "dfoptim", "bcn"] # list of required R packages

if all(rpackages.isinstalled(x) for x in required_packages):
check_packages = True # True if packages are already installed
else:
check_packages = False # False if packages are not installed

if check_packages == False: # Not installed? Then install.

packages_to_install = [
x for x in required_packages if not rpackages.isinstalled(x)
]

if len(packages_to_install) > 0:
base = importr("base")
utils = importr("utils")
base.options(
repos=base.c(
techtonique="https://techtonique.r-universe.dev",
CRAN="https://cran.rstudio.com/",
# Install R packages
commands1_lm = 'base::system.file(package = "bcn")' # check is installed
commands2_lm = 'base::system.file("bcn_r", package = "bcn")' # check is installed locally
exec_commands1_lm = subprocess.run(['Rscript', '-e', commands1_lm], capture_output=True, text=True)
exec_commands2_lm = subprocess.run(['Rscript', '-e', commands2_lm], capture_output=True, text=True)

if (len(exec_commands1_lm.stdout) == 7 and len(exec_commands2_lm.stdout) == 7): # kind of convoluted, but works

required_packages = ["Rcpp", "dfoptim", "bcn"] # list of required R packages

if all(rpackages.isinstalled(x) for x in required_packages):
check_packages = True # True if packages are already installed
else:
check_packages = False # False if packages are not installed

if check_packages == False: # Not installed? Then install.

packages_to_install = [
x for x in required_packages if not rpackages.isinstalled(x)
]

if len(packages_to_install) > 0:
base = importr("base")
utils = importr("utils")
base.options(
repos=base.c(
techtonique="https://techtonique.r-universe.dev",
CRAN="https://cran.rstudio.com/",
)
)
)
try:
utils.install_packages(StrVector(packages_to_install))
except Exception as e1:
try:
subprocess.run(['mkdir', '-p', 'bcn_r'])
utils.install_packages(StrVector(packages_to_install), lib_loc = StrVector(['bcn_r']))
except Exception as e2:
subprocess.run(["mkdir", "-p", "bcn_r"], check=True)
command1 = "Rscript -e \"try(utils::install.packages(c('Rcpp', 'dfoptim'), lib='bcn_r', repos='https://cran.rstudio.com', dependencies = TRUE), silent=TRUE)\""
subprocess.run(command1, shell=True, check=True)
command2 = "Rscript -e \"try(utils::install.packages('bcn', lib='bcn_r', repos='https://techtonique.r-universe.dev', dependencies = TRUE), silent=TRUE)\""
subprocess.run(command2, shell=True, check=True)

check_packages = True
utils.install_packages(StrVector(packages_to_install))
except Exception as e1:
try:
subprocess.run(['mkdir', '-p', 'bcn_r'])
utils.install_packages(StrVector(packages_to_install), lib_loc = StrVector(['bcn_r']))
except Exception as e2:
subprocess.run(["mkdir", "-p", "bcn_r"], check=True)
command1 = "Rscript -e \"try(utils::install.packages(c('Rcpp', 'dfoptim'), lib='bcn_r', repos='https://cran.rstudio.com', dependencies = TRUE), silent=TRUE)\""
subprocess.run(command1, shell=True, check=True)
command2 = "Rscript -e \"try(utils::install.packages('bcn', lib='bcn_r', repos='https://techtonique.r-universe.dev', dependencies = TRUE), silent=TRUE)\""
subprocess.run(command2, shell=True, check=True)

check_packages = True

base = importr("base")
try:
Expand Down

0 comments on commit 667caa5

Please sign in to comment.