@@ -23,15 +23,20 @@ check_data_format <- function(data_format, format_out){
23
23
# ' Convert chromatogram format
24
24
# ' @author Ethan Bass
25
25
# ' @noRd
26
- convert_chrom_format <- function (x , format_out ){
26
+ convert_chrom_format <- function (x , format_out , data_format = NULL ){
27
+ if (is.null(data_format )){
28
+ data_format <- attr(x , " data_format" )
29
+ }
27
30
if (inherits(x , format_out )){
28
31
return (x )
29
32
} else if (format_out == " matrix" ){
30
33
return (as.matrix(x ))
31
34
} else if (format_out == " data.frame" ){
32
35
return (as.data.frame(x ))
33
36
} else if (format_out == " data.table" ){
34
- return (data.table :: as.data.table(x ))
37
+ return (data.table :: as.data.table(x , keep.rownames = ifelse(data_format == " wide" ,
38
+ yes = " rt" , no = FALSE ))
39
+ )
35
40
}
36
41
}
37
42
@@ -363,54 +368,63 @@ split_at <- function(x, pos) unname(split(x, cumsum(seq_along(x) %in% pos)))
363
368
364
369
# ' Configure python environment
365
370
# '
366
- # ' Configures reticulate environment for parsers that have python dependencies.
367
- # ' Deprecated as this should no longer be necessary with reticulate \code{v1.41.0}.
371
+ # ' Configures python virtual environment or conda environment for parsers that
372
+ # ' have python dependencies, according to the value of \code{what}. While this
373
+ # ' should not be necessary in most cases starting with reticulate \code{v1.41.0},
374
+ # ' this function can be used to create a dedicated chromConverter environment.
368
375
# '
369
376
# ' @name configure_python_environment
370
- # ' @param parser Either \code{aston}, \code{rainbow}, or \code{olefile} (for
371
- # ' \code{read_shimadzu_lcd}).
372
- # ' @param return_boolean Logical. Whether to return a Boolean value indicating
373
- # ' if the chromConverter environment is correctly configured.
374
- # ' @return If \code{return_boolean} is \code{TRUE}, returns a Boolean value
375
- # ' indicating whether the chromConverter environment is configured correctly.
376
- # ' Otherwise, there is no return value.
377
+ # ' @param envname The name of, or path to, a Python virtual environment.
378
+ # ' @param what What kind of virtual environment to create. A python virtual
379
+ # ' environment (\code{"venv"}) or a conda environment (\code{"conda"}).
380
+ # ' @param python Argument to \code{reticulate::virtualenv_create}, specifying
381
+ # ' the path to a Python interpreter.
382
+ # ' @param ... Additional arguments to [reticulate::virtualenv_create] or
383
+ # ' [reticulate::conda_create] according to the value of \code{what}.
384
+ # ' @return There is no return value.
385
+ # ' @section Side effects:
386
+ # ' Creates and configures either a python virtual environment or conda
387
+ # ' environment (according to the value of \code{what}) with all the packages
388
+ # ' required for running chromConverter.
377
389
# ' @author Ethan Bass
378
390
# ' @import reticulate
379
391
# ' @keywords internal
380
392
# ' @export
393
+ # ' @md
381
394
382
- configure_python_environment <- function (parser = " all" , return_boolean = FALSE ){
383
- warning(" This function is deprecated as of chromConverter v0.7.4 as
384
- miniconda should no longer be necessary to load python dependencies. Continue anyway...? (y/n)" ,
385
- immediate. = TRUE )
386
- continue <- readline()
387
- if (continue %in% c(' y' , " Y" , " YES" , " yes" , " Yes" )){
388
- parser <- match.arg(tolower(parser ), c(" all" , " aston" , " olefile" , " rainbow" ))
389
- install <- FALSE
390
- if (! dir.exists(reticulate :: miniconda_path())){
391
- install <- readline(sprintf(" It is recommended to install miniconda in your R library to use %s parsers. Install miniconda now? (y/n)" ,
392
- ifelse(parser == " all" , " python-based" , parser )))
393
- if (install %in% c(' y' , " Y" , " YES" , " yes" , " Yes" )){
394
- reticulate :: install_miniconda()
395
- }
396
- }
397
- env <- reticulate :: configure_environment(" chromConverter" )
398
- if (! env ){
399
- reqs <- get_parser_reqs(parser )
400
- reqs_available <- sapply(reqs , reticulate :: py_module_available )
401
- if (! all(reqs_available )){
402
- reticulate :: conda_install(envname = " chromConverter" ,
403
- reqs [which(! reqs_available )], pip = TRUE )
404
- }
405
- }
406
- assign_fn <- switch (parser , aston = assign_trace_file(),
407
- rainbow = assign_rb_read(),
408
- function (){})
409
- assign_fn()
410
- if (return_boolean ){
411
- env
395
+ configure_python_environment <- function (what = c(" venv" , " conda" ),
396
+ envname = " chromConverter" ,
397
+ python = reticulate :: virtualenv_starter(),
398
+ ... ){
399
+ what <- match.arg(what , c(" venv" , " conda" ))
400
+ packages <- c(" Aston" , " olefile" , " pandas" , " rainbow-api" , " scipy" )
401
+ install <- FALSE
402
+ if (! dir.exists(reticulate :: miniconda_path())){
403
+ install <- readline(sprintf(" It is recommended to install miniconda in your R library to use %s parsers. Install miniconda now? (y/n)" ))
404
+ if (install %in% c(' y' , " Y" , " YES" , " yes" , " Yes" )){
405
+ reticulate :: install_miniconda()
412
406
}
413
407
}
408
+ check_name <- switch (what , " venv" = reticulate :: virtualenv_exists ,
409
+ " conda" = reticulate :: condaenv_exists )
410
+ exists <- check_name(envname )
411
+ if (exists ){
412
+ stop(sprintf(' The %s environment, "%s" already exists. To create a new environment,
413
+ please remove the existing environment first using `%s("%s")`.' ,
414
+ switch (what ," venv" = " virtual" , " conda" = " conda" ), envname ,
415
+ switch (what , " venv" = " reticulate::virtualenv_remove" ,
416
+ " conda" = " reticulate::conda_remove" ),
417
+ envname ))
418
+ }
419
+ if (what == " venv" ){
420
+ reticulate :: virtualenv_create(envname = envname , packages = packages ,
421
+ python = python , ... )
422
+ } else if (what == " conda" ){
423
+ reticulate :: conda_create(envname = envname ,
424
+ packages = c(" olefile" , " pandas" , " scipy" ), ... )
425
+ reticulate :: conda_install(envname = envname ,
426
+ packages = c(" Aston" , " rainbow-api" ), pip = TRUE )
427
+ }
414
428
}
415
429
416
430
# ' Get required python packages for a parser
0 commit comments