diff --git a/.Rbuildignore b/.Rbuildignore new file mode 100644 index 0000000000000000000000000000000000000000..b49d6fd2bfa6f93457b98ab6fd0e47d1e6e0a941 --- /dev/null +++ b/.Rbuildignore @@ -0,0 +1,3 @@ +^DCEsim\.Rproj$ +^\.Rproj\.user$ +^LICENSE\.md$ diff --git a/.Rhistory b/.Rhistory new file mode 100644 index 0000000000000000000000000000000000000000..3219d485bcfe5dc47d152bcf5fa1af3c4f3cba51 --- /dev/null +++ b/.Rhistory @@ -0,0 +1,23 @@ +options(prompt = prompt::prompt_git() ) +install.packages("prompt") +options(prompt = prompt::prompt_git() ) +usethis::edit_r_profile() +options(prompt = prompt::prompt_git() ) +options(prompt = "hello" ) +asdf +options(prompt = prompt::prompt_git() ) +fasjh +prompt::prompt_git() +git_branch() +prompt::prompt_git(git_branch()) +prompt::git_branch() +usethis::edit_r_profile() +options(prompt = prompt::git_branch() ) +options(prompt = paste0(prompt::git_branch(), "> ") ) +options(prompt = paste0(prompt::git_branch(), " > ") ) +if (interactive()) prompt::set_prompt(prompt::prompt_git)) +if (interactive()) prompt::set_prompt(prompt::prompt_git) +if (interactive()) prompt::set_prompt(prompt::prompt_git) +devtools::check() +devtools::load_all +devtools::load_all() diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..cd67eac6691ca75ea8d272e449c12b35e8b13b14 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.Rproj.user diff --git a/DCEsim.Rproj b/DCEsim.Rproj new file mode 100644 index 0000000000000000000000000000000000000000..69fafd4b6dddad27500cfc67efb9fb16e86a96bd --- /dev/null +++ b/DCEsim.Rproj @@ -0,0 +1,22 @@ +Version: 1.0 + +RestoreWorkspace: No +SaveWorkspace: No +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 +Encoding: UTF-8 + +RnwWeave: Sweave +LaTeX: pdfLaTeX + +AutoAppendNewline: Yes +StripTrailingWhitespace: Yes +LineEndingConversion: Posix + +BuildType: Package +PackageUseDevtools: Yes +PackageInstallArgs: --no-multiarch --with-keep.source +PackageRoxygenize: rd,collate,namespace diff --git a/DESCRIPTION b/DESCRIPTION new file mode 100644 index 0000000000000000000000000000000000000000..268a44c53ad12b92784a2a7248f7ec66b08fa3d2 --- /dev/null +++ b/DESCRIPTION @@ -0,0 +1,19 @@ +Package: simulateDCE +Title: Simulate data for discrete choice experiments +Version: 0.0.0.9000 +Authors@R: + person("Julian", "Sagebiel", , "julian.sagebiel@idiv.de", role = c("aut", "cre"), + comment = c(ORCID = "YOUR-ORCID-ID")) +Description: A package that supports simulating choice experiment data for given designs. It helps to quickly test different designs against each other. +License: MIT + file LICENSE +Encoding: UTF-8 +Roxygen: list(markdown = TRUE) +RoxygenNote: 7.2.2 +Imports: + dplyr, + readr, + stringr, + tidyr +Suggests: + testthat (>= 3.0.0) +Config/testthat/edition: 3 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..d1a8a0859eeeecc0e8d731d2710596c982938a17 --- /dev/null +++ b/LICENSE @@ -0,0 +1,2 @@ +YEAR: 2023 +COPYRIGHT HOLDER: simulateDCE authors diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000000000000000000000000000000000000..5d934d11fed526ec853c6c0cb4f860b079b1e055 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +# MIT License + +Copyright (c) 2023 simulateDCE authors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/NAMESPACE b/NAMESPACE new file mode 100644 index 0000000000000000000000000000000000000000..d7d3adc5a239e0f54542e7eec5e0d4cfee45b2d5 --- /dev/null +++ b/NAMESPACE @@ -0,0 +1,3 @@ +# Generated by roxygen2: do not edit by hand + +export(readdesign) diff --git a/R/readdesign.R b/R/readdesign.R new file mode 100644 index 0000000000000000000000000000000000000000..b0f58bcad13e606b3a3dfe210e213a385232376a --- /dev/null +++ b/R/readdesign.R @@ -0,0 +1,30 @@ + + + + +#' Creates a dataframe with the design. +#' +#' @param design The path to a design file +#' @param designtype Is it a design created with ngene or with spdesign. Ngene desings should be stored as the standard .ngd output. spdesign should be the spdesign object design$design +#' +#' @return a dataframe +#' @export +#' +#' @examples \dontrun{readdesign("Projects/test/Designs/firstdesign.ngd", "ngene")} +#' +readdesign <- function(design = designfile, designtype = destype) { + design <- switch(designtype, + "ngene" = readr::read_delim(design, + delim = "\t", + escape_double = FALSE, + trim_ws = TRUE, + col_select = c(-Design, -tidyr::starts_with("...")), + name_repair = "universal", show_col_types = FALSE + ) |> + dplyr::filter(!is.na(Choice.situation)), + "spdesign" = as.data.frame(readRDS(design)) |> + dplyr::mutate(Choice.situation = 1:dplyr::n()) |> + dplyr::rename_with(~ stringr::str_replace(., pattern = "_", "\\."), everything()), + stop("Invalid value for design. Please provide either 'ngene' or 'spdesign'.") + ) +} diff --git a/man/readdesign.Rd b/man/readdesign.Rd new file mode 100644 index 0000000000000000000000000000000000000000..441e9968841c73c54b28a101eed25b4ff2ef28c3 --- /dev/null +++ b/man/readdesign.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/readdesign.R +\name{readdesign} +\alias{readdesign} +\title{Creates a dataframe with the design.} +\usage{ +readdesign(design = designfile, designtype = destype) +} +\arguments{ +\item{design}{The path to a design file} + +\item{designtype}{Is it a design created with ngene or with spdesign. Ngene desings should be stored as the standard .ngd output. spdesign should be the spdesign object design$design} +} +\value{ +a dataframe +} +\description{ +Creates a dataframe with the design. +} +\examples{ +\dontrun{readdesign("Projects/test/Designs/firstdesign.ngd", "ngene")} + +} diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 0000000000000000000000000000000000000000..54b85629fb05d0fab04cc555ca808741c06cccd1 --- /dev/null +++ b/tests/testthat.R @@ -0,0 +1,12 @@ +# This file is part of the standard setup for testthat. +# It is recommended that you do not modify it. +# +# Where should you do additional test configuration? +# Learn more about the roles of various files in: +# * https://r-pkgs.org/tests.html +# * https://testthat.r-lib.org/reference/test_package.html#special-files + +library(testthat) +library(simulateDCE) + +test_check("simulateDCE")