Skip to content
Snippets Groups Projects
Commit e2ae219a authored by thierry balliau's avatar thierry balliau
Browse files

creation fonction mcq.write

aide a faire
parent 470781ae
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,7 @@ Package: MCQR
Type: Package
Title: a R Package for Analysis of Mass-Spectrometry-Based Proteomics Data
Version: 0.5.2
Date: 2021-08-31
Date: 2021-09-06
Author: PAPPSO team (pappso-projetsbioinfo@groupes.renater.fr)
Maintainer: PAPPSO team <pappso-projetsbioinfo@groupes.renater.fr>
Description: R package dedicated to the statistical analysis of mass-spectrometry-based proteomic data.
......
......@@ -139,6 +139,7 @@
export("mcq.write.merge")
export("mcq.write.metadata.template")
export("mcq.write.synthesis")
export("mcq.write")
# Other Functions
......
#### Fonction pour effectuer toute les operation d'ecriture de fichier de resultat pour mcqr
### peut prendre en entrée des dataframes uniquement (en empilé ou depilé)
### permet d'exporter en ods ou en tsv au choix
### pour le format tsv on doit ajouter le separateur de decimal et de colonne
### vu que le fichier peut etre en csv ou en ods ne pas mettre d'extension dans le nom du fichier (ou bien le supprimer si existant )
### extension en fonction du format et des séparateur
mcq.write <- function(object, type="text", sep="\t", dec=".", file="export"){
### check argument
error_messages = list()
j=1
if(!is.character(type) || !(type %in% c("flat", "ods"))){
error_messages[[j]] = "The 'type' argument must be 'flat' or 'ods'."
j=j+1
}
if(!is.character(sep) && !(type %in% c("\t", ",", ";"))){
error_messages[[j]] = "The 'sep' argument must be '\t', ',' or ';'."
j=j+1
}
if(!is.character(dec) && !(type %in% c("\\.", ","))){
error_messages[[j]] = "The 'sep' argument must be ',' or '.'."
j=j+1
}
if(!is.character(file)){
error_messages[[j]] = "The 'file' argument must be characters."
j=j+1
}
if(str_count(file, "\\.") != 0){
error_messages[[j]] = "Please do not specify extension for file argument. It will be automatically add."
j=j+1
}
if(sep == dec){
error_messages[[j]] = "It is not possible to have the same argument for the sep argument and the dec argument."
j=j+1
}
if(!("data.frame" %in% class(object))){
error_messages[[j]] = "the object must be a data.frame."
j=j+1
}
if (length(error_messages) != 0){
stop(paste("Error on argument format:\n", paste(error_messages, collapse="\n"), sep=""))
}
if(type == "ods"){
filename = paste0(file, ".ods")
write_ods(object, filename, sheet = "Sheet1")
}else if(type == "flat"){
if(sep == "\t"){
filename = paste0(file, ".tsv")
}else{
filename = paste0(file, ".csv")
}
write.table(object, file=filename, sep=sep, dec=dec, row.names=F)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment