Как решить "отсутствующие аргументы, не разрешенные в вызовах" списка "" для разработки пакета R? - PullRequest
0 голосов
/ 17 января 2020

Я создаю пакет R и пытаюсь запустить devtools :: check (). Результаты выглядят следующим образом:

проверка кода R на возможные проблемы ... ПРИМЕЧАНИЕ myFunction: пропущенные аргументы недопустимы в вызовах 'list'

Как узнать, какие аргумент отсутствует? Что это хотя бы значит? У меня есть большая функция со многими переменными.

Вот часть функции: она в основном создает html -отчет для моего анализа биоинформатики.

#' @title cAMARETTO_HTMLreport
#' Creates a HTMLreport for the community AMARETTO results
#'
#' @param cAMARETTOresults The output of the Results function.
#' @param cAMARETTOnetworkM The output of the Module Network function.
#' @param cAMARETTOnetworkC The output of the Identify Communities function.
#' @param output_address The output repository for the HTML report.
#' @param HTMLsAMARETTOlist A list with AMARETTO reports to link with the 
#' Community AMARETTO report. If NULL, no links are added.
#' @param CopyAMARETTOReport Boolean to indicate if the AMARETTO reports
#' needs to be copied in the AMARETTO report directory.
#' In this way links are contained when moving the HTML directory.
#' @param hyper_geo_reference A reference gmt file to perform 
#' the Hyper Geometric Test.
#' @param NrCores Number of Cores to use during generation of the HTML report.
#' @param driverGSEA if TRUE, driver genes beside the target genes will also 
#' be included for hypergeometric test. 
#' @param hyper_geo_reference_gp Hypergeometric test table 
#' for genetic perturbation
#' @param hyper_geo_reference_cp Hypergeometric test table for
#'  chemical perturbation
#' @param PhenotypeTablesList List of Phenotype Association Tables 
#' for different AMARETTO runs.
#'
#' @return A set of HTMLs, giving caracteristics of the communities
#' @importFrom igraph as_data_frame degree E graph_from_data_frame
#'  layout_with_fr V graph.data.frame norm_coords edge.betweenness.community
#' @import DT
#' @import rmarkdown
#' @import utils
#' @importFrom stringr str_order
#' @importFrom dplyr arrange group_by left_join mutate select summarise  
#' rename  filter everything pull distinct mutate one_of pull summarise
#' @importFrom tibble add_row tibble column_to_rownames rownames_to_column
#' @importFrom knitr knit_meta 
#' @importFrom reshape2 dcast
#' @importFrom utils stack data
#' @importFrom tidyr separate unite
#' @importFrom R.utils insert
#' @examples 
#' try(
#' cAMARETTO_HTMLreport(cAMARETTOresults,
#'   cAMARETTOnetworkM,
#'   cAMARETTOnetworkC,
#'   HTMLsAMARETTOlist = HTMLsAMARETTOlist,
#'   hyper_geo_reference = gmtfile,
#'   output_address= "./")
#' )
#' @export
cAMARETTO_HTMLreport <- function(cAMARETTOresults,
                                cAMARETTOnetworkM,
                                cAMARETTOnetworkC,
                                PhenotypeTablesList = NULL,
                                output_address ="./",
                                HTMLsAMARETTOlist = NULL,
                                CopyAMARETTOReport = TRUE,
                                hyper_geo_reference = NULL,
                                hyper_geo_reference_gp = NULL,
                                hyper_geo_reference_cp = NULL,
                                driverGSEA = TRUE,
                                NrCores=2){

    ##################################### Bioconductor Considerations :
    Run_Names <- AMARETTOres <- Weights <- Color<- Type<- GeneNames<-NULL
    GeneName <- Community <- TypeColored <- Community_key<-NULL
    Community_type<- ModuleNr<-NULL
    ModuleName <- Run <- Genes <- q.value<-NULL
    #####################################

    RunInfoList<-InitialCheckInputs(cAMARETTOresults=cAMARETTOresults,
                                    output_address,
                                    HTMLsAMARETTOlist=cAMARETTOresults,
                                    CopyAMARETTOReport,
                                    hyper_geo_reference,
                                    hyper_geo_reference_gp,
                                    hyper_geo_reference_cp)
    RunInfo<-RunInfoList$RunInfo
    RunInfo2<-RunInfoList$RunInfo2
    full_path<-RunInfoList$full_path
    HTMLsAMARETTOlist<-RunInfoList$HTMLsAMARETTOlist
    #====================================================================
    # Extract main dataframes
    com_gene_df<-suppressWarnings(
        ComRunModGenInfo(cAMARETTOresults,cAMARETTOnetworkM,
                        cAMARETTOnetworkC))
    comm_info <-suppressWarnings(
        cAMARETTO_InformationTable(cAMARETTOnetworkM,cAMARETTOnetworkC))
    #====================================================================
    Runs_AMARETTOs_info<-com_gene_df%>%
        dplyr::select(Run_Names,AMARETTOres)%>%
        dplyr::distinct()%>%
        dplyr::mutate(Run_Names = RunHyperLink(Run_Names,AMARETTOres,
                    HTMLsAMARETTOlist,CopyAMARETTOReport))%>%
                        filter(AMARETTOres==1)%>%select(Run_Names)
    #====================================================================
    ComModulesLink<-CommunityModuleTableCreate(cAMARETTOresults,
                                                cAMARETTOnetworkM, 
                                                cAMARETTOnetworkC,
                                                HTMLsAMARETTOlist,
                                                CopyAMARETTOReport)
    #====================================================================
    com_gene_df<-com_gene_df%>%
        dplyr::mutate(Color=sapply(as.numeric(Weights), function(x){
        if(is.na(x)){
            return("")
        }
        else if(x>0){
            return("darkred")
        }
        else if(x<0){
            return("darkblue")
        }
        else {
            return("darkgreen")
        }
    }))%>%dplyr::mutate(TypeColored=paste0('<font color=',
                                            Color,
                                            '>',
                                            Type,
                                            '</font>'))
    #========================================================
    #[stringr::str_order(Community, numeric = TRUE),]
    geneCardURL<-"<a href=\"https://www.genecards.org/cgi-bin/carddisp.pl?gene="
    GeneComLink<-com_gene_df%>%
        filter(AMARETTOres==1)%>%
        dplyr::rename(GeneName = GeneNames)%>%
        dplyr::mutate(GeneName = paste0(geneCardURL,
                                        GeneName,
                                        "\">",
                                        GeneName,
                                        "</a>"))%>%
        dplyr::select(c(GeneName,Community,TypeColored,
                        Community_key,Community_type))%>%
        dplyr::rename(Type=TypeColored)%>%
        dplyr::mutate(Community = CommunityHyperLink(Community,Community_key,
                                                        Community_type))%>%
        dplyr::arrange(GeneName)%>%
        select(-Community_key,-Community_type)%>%
        select(GeneName,everything())%>%
        distinct()
    #=======================================================================
    #GeneComLink<-GeneComLink[stringr::str_order(GeneComLink$Community,
    #numeric = TRUE),]
    #=======================================================================
    #adding Community to driver genes table 
    Comm_Drivers<-com_gene_df%>%
        dplyr::filter(Type=="Driver")%>%
        dplyr::mutate(GeneNames=paste0(geneCardURL,
                                        GeneNames,
                                        "\">",
                                        GeneNames,
                                        "</a>"))%>%
        dplyr::group_by(Community_key,Run_Names,Community_type,Community)%>%
        dplyr::summarise(Drivers=paste(unique(sort(GeneNames)),collapse = ", "))

    Comm_Drivers<-data.frame(Comm_Drivers)%>%
        dplyr::mutate(Community = CommunityHyperLink(Community,
                                                        Community_key,
                                                        Community_type))

    Comm_Drivers<-Comm_Drivers[stringr::str_order(Comm_Drivers$Community,
                                numeric = TRUE),]
    #===================================================================
    #HGT to test for gene set enrichment
    # avoid showing datatable size-related warnings.
    #===================================================================
    # add phenotype table
    if (!is.null(PhenotypeTablesList)){
        phenotype_table_all<-CreatePhenotypeTable(cAMARETTOresults,
                                                    cAMARETTOnetworkM,
                                                    cAMARETTOnetworkC,
                                                    PhenotypeTablesList)
    }
    #===================================================================
    # do hypergeometric test
    if(!is.null(hyper_geo_reference)){
        if (is.character(hyper_geo_reference)){
            all_hgt_output<-CreateHyperGeoTestAll(cAMARETTOresults,
                                                    cAMARETTOnetworkM,
                                                    cAMARETTOnetworkC,
                                                    hyper_geo_reference,
                                                    driverGSEA)
                                                }
        else if (is.data.frame(hyper_geo_reference)){
            all_hgt_output<-hyper_geo_reference
        }
    else{
        stop("hyper_geo_reference is not in the correct format!")
        }
    }
    #=====================================================================
    #=====================================================================
    # do hypergeometric test
    if(!is.null(hyper_geo_reference_gp)){
        if (is.character(hyper_geo_reference_gp)){
            all_hgt_output_gp<-CreateHyperGeoTestAll(cAMARETTOresults,
                                                    cAMARETTOnetworkM,
                                                    cAMARETTOnetworkC,
                                                    hyper_geo_reference_gp,
                                                    driverGSEA)
        }
        else if (is.data.frame(hyper_geo_reference_gp)){
            all_hgt_output_gp<-hyper_geo_reference_gp
        }
    else{
        stop("hyper_geo_reference_gp is not in the correct format!")
    }
    }
    #=====================================================================
    #=====================================================================
    # do hypergeometric test
    if(!is.null(hyper_geo_reference_cp)){
        if (is.character(hyper_geo_reference_cp)){
            all_hgt_output_cp<-CreateHyperGeoTestAll(cAMARETTOresults,
                                                    cAMARETTOnetworkM,
                                                    cAMARETTOnetworkC,
                                                    hyper_geo_reference_cp,
                                                    driverGSEA)
        }
        else if (is.data.frame(hyper_geo_reference_cp)){
        all_hgt_output_cp<-hyper_geo_reference_cp
        }
        else{
            stop("hyper_geo_reference is not in the correct format!")
        }
    }
    #===================================================================

    options('DT.warn.size'=FALSE)
    buttons_list = list(list(extend ='csv'),
                        list(extend ='excel'),
                        list(extend = 'pdf', pageSize = 'A4',
                        orientation = 'landscape'),
                        list(extend ='print'), list(extend ='colvis'))
    columnDefs = list(list(className = 'dt-head-center', targets = "_all"),
                    list(className = 'text-left',targets = "_all"))
    optionsList = list(deferRender=TRUE,
                        pageLength = 10,
                        lengthMenu = c(5, 10, 20, 50, 100),
                        keys = TRUE,
                        dom = "Blfrtip", 
                        buttons = buttons_list,
                        columnDefs = columnDefs,
                        paging = TRUE)
    #=========================================================================
    # Community Pages : 
    for (ComNr in unique(com_gene_df$Community_key)){
        ModuleList<-com_gene_df%>%
            filter(Community_key==ComNr)%>%
            select(Run_Names,ModuleNr,AMARETTOres)%>%
            distinct()%>%
            mutate(ModuleNr=ModuleHyperLink(ModuleNr,Run_Names,AMARETTOres,
                                    HTMLsAMARETTOlist,
                                    CopyAMARETTOReport,page=2))%>%
                                    select(-AMARETTOres)
    DTML <- DT::datatable(ModuleList, 
                            class = "display",
                            filter = 'top',
                            extensions = c('Buttons','KeyTable'),
                            rownames = FALSE,
                            options = optionsList,
                            colnames = c("Data Set", "Module"),
                            escape = FALSE)

    #adding Gene-Module-Run tabel
    genelists_module<-com_gene_df%>%
        filter(AMARETTOres==1)%>%
        dplyr::filter(Community_key==ComNr)%>%
        dplyr::arrange(GeneNames)%>%
        dplyr::rename(Run=Run_Names)%>%
        dplyr::rename(ModuleName=ModuleNr)%>%
        dplyr::rename(Genes=GeneNames)%>%
        dplyr::select(-c(Type))%>%
        dplyr::rename(Type=TypeColored)

    geneCardURL<-"<a href=\"https://www.genecards.org/cgi-bin/carddisp.pl?gene="
    genelists_module <- genelists_module%>%
        mutate(ModuleName = ModuleHyperLink(ModuleName,
                                            Run,
                                            AMARETTOres,
                                            HTMLsAMARETTOlist,
                                            CopyAMARETTOReport,
                                            page=2))%>%
                dplyr::mutate(Genes = paste0(geneCardURL,
                                            Genes,
                                            "\">",
                                            Genes,
                                            "</a>"))%>%
                dplyr::select(c(Run,ModuleName,Genes,Type))

    DTGenes <- DT::datatable(genelists_module,
                            class = "display",
                            filter = 'top',
                            extensions = c('Buttons','KeyTable'),
                            rownames = FALSE,
                            options = optionsList,
                            colnames = c("Data Set", "Module",
                                        "Gene", "Gene Type"),
                            escape=FALSE)

    if(!is.null(hyper_geo_reference)) {
        DTGSEA<-create_hgt_datatable(all_hgt_output,
                                    com_table=TRUE,
                                    ComNr = ComNr)
    } else {
        DTGSEA <- "Genesets were not analysed as they were not provided."
    }
    if(!is.null(hyper_geo_reference_gp)) {
        DTGSEA_gp<-create_hgt_datatable(all_hgt_output_gp,
                                        com_table=TRUE,
                                        ComNr = ComNr)
    } else {
        DTGSEA_gp <- "Genesets were not analysed as they were not provided."
    }
    if(!is.null(hyper_geo_reference_cp)) {
        DTGSEA_cp<-create_hgt_datatable(all_hgt_output_cp,
                                        com_table=TRUE,
                                        ComNr = ComNr)
    } else {
        DTGSEA_cp<- "Genesets were not analysed as they were not provided."
    }
    # add phenotype table for each community page
    if (!is.null(PhenotypeTablesList)){
        phenotype_table_community<-phenotype_table_all%>%
        dplyr::filter(Community_key==ComNr)%>%
        select(Run_Names,everything())%>%
        dplyr::mutate(ModuleNr=ModuleHyperLink(ModuleNr,
                                                Run_Names,
                                                AMARETTOres,
                                                HTMLsAMARETTOlist,
                                                CopyAMARETTOReport,
                                                page=2))%>%
        select(-AMARETTOres)

        phenotype_table_community<-phenotype_table_community%>%
            dplyr::select(-Community_key,-Community,-Community_type)%>%
            arrange(q.value)

        DTPhC<-DT::datatable(phenotype_table_community,
                            class = "display",
                            filter = 'top',
                            extensions = c('Buttons','KeyTable'),
                            rownames = FALSE,
                            colnames=c("Data Set","Module",
                                    "Phenotype","Statistics Test",
                                    "P-value","FDR Q-value",
                                    "Descriptive Statistics"),
                            options = optionsList,
                            escape = FALSE)
    }
    else{ DTPhC = "Phenotype Statistical Analysis is not provided" }

    comm_name<-com_gene_df%>%
        filter(Community_key==ComNr)%>%
        select(Community,Community_key)%>%
        distinct()%>%
        pull(Community)
    if (grepl("Not in", comm_name)){
        ComTitle = comm_name
    }
    else{
        ComTitle = paste0("Community ",comm_name)
    }
    # cleaning memory, avoiding memory to be overloaded
    knitr::knit_meta(class=NULL, clean = TRUE)  
    rmarkdown::render(
    system.file("templates/community_page_template/TemplateCommunityPage.Rmd",
        package = "CommunityAMARETTO"),
        output_dir = paste0(full_path, "/communities"),
        output_file = paste0("Community_",ComNr,".html"),
        params = list(
            ComNr = ComNr,
            ComTitle = ComTitle,
            DTGSEA = DTGSEA,
            DTGSEA_gp = DTGSEA_gp,
            DTGSEA_cp = DTGSEA_cp,
            DTML = DTML,
            DTGenes = DTGenes,
            DTPhC = DTPhC,
            cAMARETTOnetworkM = cAMARETTOnetworkM,
            cAMARETTOnetworkC = cAMARETTOnetworkC
            ), quiet = TRUE)
    }
    file_remove<-suppressWarnings(
        suppressMessages(file.remove(paste0(full_path,
            "/communities/Community_",
            c(seq_len(length(unique(com_gene_df$Community_key)))),"_files"))))
    file_remove<-suppressWarnings(
        suppressMessages(file.remove(paste0(full_path,"index_files"))))
    #========================================================================
    # index page : 
    DTRunInfo<-datatable(Runs_AMARETTOs_info,
            class = "display",
            filter = 'top',
            extensions = c('Buttons','KeyTable'),
            escape=FALSE,
            rownames = FALSE,
            options=optionsList,
            colnames = c("AMARETTO Report"))

    ComModulesLink<-ComModulesLink %>%
        dplyr::rename(Edges="numTotalEdgesInCommunity",
                            "Fraction Edges"="fractEdgesInVsOut",
                            "Fraction Size"="CommsizeFrac")
    DTComModulesLink<-datatable(ComModulesLink, 
                                class = "display",
                                filter = 'top',
                                extensions = c('Buttons','KeyTable'),
                                rownames = FALSE,
                                options = optionsList,
                                escape=FALSE) %>%
                formatSignif(c("Fraction Edges","Fraction Size"),2)

    DTGeneComLink<-datatable(GeneComLink, 
                            class = "display",
                            filter = 'top',
                            extensions = c('Buttons','KeyTable'),
                            rownames = FALSE,
                            options = optionsList,
                            colnames = c("Gene", "Community", "Gene Type"),
                            escape=FALSE)

    #=========================================
    if (!is.null(hyper_geo_reference)) {
        DTGSEAall <-create_hgt_datatable(all_hgt_output, com_table=FALSE)
    }
    else{
        DTGSEAall <- "Genesets were not analysed as they were not provided."
    }

    if (!is.null(hyper_geo_reference_gp)) {
        DTGSEAall_gp <-create_hgt_datatable(all_hgt_output_gp, com_table=FALSE)
    }
    else{
        DTGSEAall_gp <- "Genesets were not analysed as they were not provided."
    }

    if (!is.null(hyper_geo_reference_cp)) {
        DTGSEAall_cp <-create_hgt_datatable(all_hgt_output_cp, com_table=FALSE)
    }
    else{
        DTGSEAall_cp <- "Genesets were not analysed as they were not provided."
    }
    #=========================================
    Comm_Drivers<-Comm_Drivers%>%
        select(-Community_key,-Community_type)%>%
        select(Community,everything())
    DTComDrivers<- DT::datatable(Comm_Drivers,
                                class = "display",
                                filter = 'top',
                                extensions = c('Buttons','KeyTable'),
                                rownames = FALSE,
                                options = optionsList,
                                colnames = c("Community",
                                            "Data Set",
                                            "Driver Genes"),
                                escape = FALSE)

    # add phenotype table for index page
    if (!is.null(PhenotypeTablesList)){
        phenotype_table_all<-phenotype_table_all%>%
            dplyr::mutate(ModuleNr=ModuleHyperLink(ModuleNr,
                                                    Run_Names,
                                                    AMARETTOres,
                                                    HTMLsAMARETTOlist,
                                                    CopyAMARETTOReport))%>%
            select(-AMARETTOres)
        phenotype_table_all<-phenotype_table_all%>%
            dplyr::mutate(Community = CommunityHyperLink(Community,
                                                        Community_key,
                                                        Community_type))%>%
            select(-Community_key,-Community_type)%>%
            select(Community,Run_Names,everything())%>%
            arrange(q.value,Community)

    DTPh<-DT::datatable(phenotype_table_all,
                        class = "display",
                        filter = 'top',
                        extensions = c('Buttons','KeyTable'),
                        rownames = FALSE,
                        options = optionsList,
                        colnames=c("Community","Data Set","Module",
                                    "Phenotype","Statistics Test",
                                    "P-value","FDR Q-value",
                                    "Descriptive Statistics"),
                        escape = FALSE)
    }
    else{ DTPh = "Phenotype Statistical Analysis is not provided" }

    driversFreqTbl<-DriversSharedTbl(cAMARETTOresults,
                                    cAMARETTOnetworkM,
                                    cAMARETTOnetworkC)%>%
        left_join(com_gene_df%>%
                    select(Community_key,Community,Community_type)%>%
                    distinct(),by="Community_key")%>%
                    dplyr::mutate(Community = CommunityHyperLink(Community,
                                                Community_key,
                                                Community_type))%>%
        select(-Community_key,-Community_type)%>%
        select(Community,everything())

    DTdriverFreq<- DT::datatable(driversFreqTbl,
                                class = "display",
                                filter = 'top',
                                extensions = c('Buttons','KeyTable'),
                                rownames = FALSE,
                                options = optionsList,
                                escape = FALSE)

    rmarkdown::render(
        system.file("templates/TemplateIndexPage.Rmd",
        package = "CommunityAMARETTO"),
        output_dir = full_path,
        output_file = "index.html",
        params = list(
            cAMARETTOnetworkM = cAMARETTOnetworkM,
            cAMARETTOnetworkC = cAMARETTOnetworkC,
            DTComModulesLink = DTComModulesLink,
            DTRunInfo =  DTRunInfo), quiet = TRUE)

    rmarkdown::render(
        system.file("templates/TemplateIndexPage_RunsInfo.Rmd",
                    package = "CommunityAMARETTO"),
        output_dir = full_path,
        output_file = "index_RunsInfo.html",
        params = list(DTRunInfo =  DTRunInfo), quiet = TRUE)

    rmarkdown::render(
        system.file("templates/TemplateIndexPage_AllCommunities.Rmd",
                    package = "CommunityAMARETTO"),
        output_dir = full_path,
        output_file = "index_AllCommunities.html",
        params = list(DTRunInfo =  DTRunInfo), quiet = TRUE)

    rmarkdown::render(
        system.file("templates/TemplateIndexPage_Drivers.Rmd",
                    package = "CommunityAMARETTO"),
        output_dir = full_path,
        output_file = "index_Drivers.html",
        params = list(DTdriverFreq = DTdriverFreq),quiet = TRUE)

    rmarkdown::render(
        system.file("templates/TemplateIndexPage_Drivers2.Rmd",
                    package = "CommunityAMARETTO"),
        output_dir = full_path,
        output_file = "index_Drivers2.html",
        params = list(DTComDrivers=DTComDrivers,), quiet = TRUE)

    rmarkdown::render(
    system.file("templates/TemplateIndexPage_AllGenes.Rmd",
                package = "CommunityAMARETTO"),
    output_dir = full_path,
    output_file = "index_AllGenes.html",
    params = list(DTGeneComLink = DTGeneComLink), quiet = TRUE)

    rmarkdown::render(
        system.file("templates/TemplateIndexPage_GenesetsEnrichment.Rmd",
                package = "CommunityAMARETTO"),
        output_dir = full_path,
        output_file = "index_GenesetsEnrichment.html",
        params = list(DTGSEAall = DTGSEAall), quiet = TRUE)

    rmarkdown::render(
        system.file("templates/TemplateIndexPage_GenesetsEnrichment_gp.Rmd",
                    package = "CommunityAMARETTO"),
        output_dir = full_path,
        output_file = "index_GenesetsEnrichment_gp.html",
        params = list(DTGSEAall_gp = DTGSEAall_gp), quiet = TRUE)

    rmarkdown::render(
        system.file("templates/TemplateIndexPage_GenesetsEnrichment_cp.Rmd",
        package = "CommunityAMARETTO"),
        output_dir = full_path,
        output_file = "index_GenesetsEnrichment_cp.html",
        params = list(DTGSEAall_cp = DTGSEAall_cp), quiet = TRUE)

    rmarkdown::render(
        system.file("templates/TemplateIndexPage_PhenoAssociation.Rmd",
        package = "CommunityAMARETTO"),
        output_dir = full_path,
        output_file = "index_PhenoAssociation.html",
        params = list(DTPh = DTPh), quiet = TRUE)
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...