From ee33153e088c4560a9e02dd97d46533fa8267e5e Mon Sep 17 00:00:00 2001
From: dj44vuri <julian.sagebiel@idiv.de>
Date: Tue, 19 Dec 2023 12:50:59 +0100
Subject: [PATCH] some warnings dissapeared

---
 .Rhistory                       | 54 +++++++++++++++++++++++++++++++++
 DESCRIPTION                     |  5 ++-
 NAMESPACE                       |  3 ++
 R/sim_all.R                     |  6 ++++
 R/sim_choice.R                  | 13 ++++++++
 R/simulate_choices.R            | 16 +++++-----
 R/utils.R                       | 10 ++++++
 man/download_and_extract_zip.Rd | 21 +++++++++++++
 man/sim_all.Rd                  | 11 +++++++
 man/sim_choice.Rd               | 21 +++++++++++++
 tests/manualtests.R             |  4 +--
 11 files changed, 153 insertions(+), 11 deletions(-)
 create mode 100644 man/download_and_extract_zip.Rd
 create mode 100644 man/sim_all.Rd
 create mode 100644 man/sim_choice.Rd

diff --git a/.Rhistory b/.Rhistory
index 3219d48..e3e3d24 100644
--- a/.Rhistory
+++ b/.Rhistory
@@ -21,3 +21,57 @@ if (interactive()) prompt::set_prompt(prompt::prompt_git)
 devtools::check()
 devtools::load_all
 devtools::load_all()
+devtools::document()
+devtools::document()
+devtools::check()
+usethis::use_package("formula.tools")
+usethis::use_package("formula.tools")
+devtools::check()
+usethis::use_package("purrr")
+devtools::check()
+devtools::document()
+devtools::check()
+usethis::use_package(c(‘mixl’, ‘psych’, ‘rmarkdown’, ‘tibble’, ‘tictoc’))
+usethis::use_package(c("mixl", "psych", "rmarkdown", "tibble", "tictoc"))
+usethis::use_package(c("mixl"))
+usethis::use_package(c( "tictoc"))
+usethis::use_package(c(tibble",))
+l
+)
+,
+}
+q
+.
+ajsdflakjdf
+"
+usethis::use_package(c("tibble"))
+usethis::use_package(c("mixl", "psych", "rmarkdown", "tibble", "tictoc"))
+usethis::use_package(c( "rmarkdown"))
+usethis::use_package(c("psych"))
+devtools::check()
+load_all()
+devtools::load_all()
+system.file("extdata","Rbook" ,package = "simulateDCE")
+source("~/share/groups/bioecon/Julian/simulateDCE/tests/manualtests.R")
+source("~/share/groups/bioecon/Julian/simulateDCE/tests/manualtests.R")
+source("~/share/groups/bioecon/Julian/simulateDCE/tests/manualtests.R")
+source("~/share/groups/bioecon/Julian/simulateDCE/R/simulate_choices.R")
+source("~/share/groups/bioecon/Julian/simulateDCE/tests/manualtests.R")
+devtools::document()
+devtools::load_all()
+?basename
+devtools::document()
+usethis::use_package("evd")
+source("~/share/groups/bioecon/Julian/simulateDCE/tests/manualtests.R")
+source("~/share/groups/bioecon/Julian/simulateDCE/tests/manualtests.R")
+package_version(dplyr)
+package_version("dplyr")
+packageVersion("dplyr")
+usethis::use_package("dplyr, 1.1.4)
+""
+"
+usethis::use_package("dplyr",min_version =  "1.1.4")
+devtools::document()
+packageVersion("dplyr")
+packageVersion("dplyr")
+install.packages("dplyr")
diff --git a/DESCRIPTION b/DESCRIPTION
index 4bfb583..3b218f3 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -10,13 +10,16 @@ Encoding: UTF-8
 Roxygen: list(markdown = TRUE)
 RoxygenNote: 7.2.2
 Imports: 
-    dplyr,
+    dplyr (>= 1.1.4),
+    evd,
     formula.tools,
     mixl,
     psych,
     purrr,
     readr,
+    reshape,
     rmarkdown,
+    stats,
     stringr,
     tibble,
     tictoc,
diff --git a/NAMESPACE b/NAMESPACE
index 2179643..e6af3a9 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -1,4 +1,7 @@
 # Generated by roxygen2: do not edit by hand
 
+export(download_and_extract_zip)
 export(readdesign)
+export(sim_all)
+export(sim_choice)
 export(simulate_choices)
diff --git a/R/sim_all.R b/R/sim_all.R
index 96c2f0e..6e30cb7 100644
--- a/R/sim_all.R
+++ b/R/sim_all.R
@@ -1,3 +1,9 @@
+#' Title
+#'
+#' @return
+#' @export
+#'
+#' @examples
 sim_all <- function(){
 
   require("stringr")
diff --git a/R/sim_choice.R b/R/sim_choice.R
index 0634ac7..74a14a7 100644
--- a/R/sim_choice.R
+++ b/R/sim_choice.R
@@ -1,3 +1,16 @@
+#' Title
+#'
+#' @param designfile
+#' @param no_sim
+#' @param respondents
+#' @param mnl_U
+#' @param utils
+#' @param destype
+#'
+#' @return
+#' @export
+#'
+#' @examples
 sim_choice <- function(designfile, no_sim=10, respondents=330, mnl_U,utils=u[[1]] ,destype) {
 
 
diff --git a/R/simulate_choices.R b/R/simulate_choices.R
index 5372556..4aa5d2d 100644
--- a/R/simulate_choices.R
+++ b/R/simulate_choices.R
@@ -14,8 +14,8 @@ simulate_choices <- function(data=datadet, utility =utils, setspp) {  #the part
 
   by_formula <- function(equation){ #used to take formulas as inputs in simulation utility function
     # //! cur_data_all may get deprecated in favor of pick
-    # pick(everything()) %>%
-    cur_data_all() |>
+    dplyr::pick(everything()) |>
+    #cur_data_all() |>
       dplyr::transmute(!!formula.tools::lhs(equation) := !!formula.tools::rhs(equation) )
   }
 
@@ -35,7 +35,7 @@ simulate_choices <- function(data=datadet, utility =utils, setspp) {  #the part
 
   cat("\n dataset final_set exists: ",exists("final_set"), "\n")
 
-  if(exists("final_set")) data = left_join(data,final_set, by = "ID")
+  if(exists("final_set")) data = dplyr::left_join(data,final_set, by = "ID")
 
   cat("\n decisiongroups exists: " ,exists("decisiongroups"))
 
@@ -62,14 +62,14 @@ simulate_choices <- function(data=datadet, utility =utils, setspp) {  #the part
   subsets<- split(data,data$group)
 
   subsets <-  purrr::map2(.x = seq_along(u),.y = subsets,
-                   ~ mutate(.y,map_dfc(u[[.x]],by_formula)))
+                   ~ dplyr::mutate(.y,purrr::map_dfc(u[[.x]],by_formula)))
 
-  data <-bind_rows(subsets)
+  data <-dplyr::bind_rows(subsets)
 
   data<- data %>%
     dplyr::rename_with(~ stringr::str_replace(.,pattern = "\\.","_"), tidyr::everything()) %>%
-    mutate(across(.cols=n,.fns = ~ rgumbel(setspp,loc=0, scale=1), .names = "{'e'}_{n}" ),
-           across(starts_with("V_"), .names = "{'U'}_{n}") + across(starts_with("e_")) ) %>% ungroup() %>%
+    dplyr::mutate(dplyr::across(.cols=n,.fns = ~ evd::rgumbel(setspp,loc=0, scale=1), .names = "{'e'}_{n}" ),
+           dplyr::across(dplyr::starts_with("V_"), .names = "{'U'}_{n}") + dplyr::across(dplyr::starts_with("e_")) ) %>% dplyr::ungroup() %>%
     dplyr::mutate(CHOICE=max.col(.[,grep("U_",names(.))])
     )   %>%
     as.data.frame()
@@ -80,7 +80,7 @@ simulate_choices <- function(data=datadet, utility =utils, setspp) {  #the part
   cat("\n data has been made \n")
 
   cat("\n First few observations \n ")
-  print(head(data))
+  print(utils::head(data))
   cat("\n \n ")
   return(data)
 
diff --git a/R/utils.R b/R/utils.R
index 89801dd..2712682 100644
--- a/R/utils.R
+++ b/R/utils.R
@@ -9,6 +9,16 @@ plot_multi_histogram <- function(df, feature, label_column) { #function to creat
 
 
 
+#' Title Downloads and extracts external data to be used in the simulation
+#'
+#' @param url the URL from where the external data can be downloaded. The external data has be wrapped in a zip file
+#' @param dest_folder The folder where the data should be stored
+#' @param zip_name Only needs to be changed if the zip file is differently named as the last part of the URL
+#'
+#' @return nothing, stores the data on the local system
+#' @export
+#'
+#' @examples
 download_and_extract_zip <- function(url, dest_folder = ".", zip_name = NULL) {
   # If zip_name is not provided, extract it from the URL
   if (is.null(zip_name)) {
diff --git a/man/download_and_extract_zip.Rd b/man/download_and_extract_zip.Rd
new file mode 100644
index 0000000..e4cbbe9
--- /dev/null
+++ b/man/download_and_extract_zip.Rd
@@ -0,0 +1,21 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/utils.R
+\name{download_and_extract_zip}
+\alias{download_and_extract_zip}
+\title{Title Downloads and extracts external data to be used in the simulation}
+\usage{
+download_and_extract_zip(url, dest_folder = ".", zip_name = NULL)
+}
+\arguments{
+\item{url}{the URL from where the external data can be downloaded. The external data has be wrapped in a zip file}
+
+\item{dest_folder}{The folder where the data should be stored}
+
+\item{zip_name}{Only needs to be changed if the zip file is differently named as the last part of the URL}
+}
+\value{
+nothing, stores the data on the local system
+}
+\description{
+Title Downloads and extracts external data to be used in the simulation
+}
diff --git a/man/sim_all.Rd b/man/sim_all.Rd
new file mode 100644
index 0000000..90c3ac1
--- /dev/null
+++ b/man/sim_all.Rd
@@ -0,0 +1,11 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/sim_all.R
+\name{sim_all}
+\alias{sim_all}
+\title{Title}
+\usage{
+sim_all()
+}
+\description{
+Title
+}
diff --git a/man/sim_choice.Rd b/man/sim_choice.Rd
new file mode 100644
index 0000000..94a36d6
--- /dev/null
+++ b/man/sim_choice.Rd
@@ -0,0 +1,21 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/sim_choice.R
+\name{sim_choice}
+\alias{sim_choice}
+\title{Title}
+\usage{
+sim_choice(
+  designfile,
+  no_sim = 10,
+  respondents = 330,
+  mnl_U,
+  utils = u[[1]],
+  destype
+)
+}
+\arguments{
+\item{destype}{}
+}
+\description{
+Title
+}
diff --git a/tests/manualtests.R b/tests/manualtests.R
index f4df9b6..cf484f0 100644
--- a/tests/manualtests.R
+++ b/tests/manualtests.R
@@ -1,6 +1,6 @@
 
 rm(list=ls())
-devtools::load_all()
+#devtools::load_all()
 
 
 
@@ -38,7 +38,7 @@ u<- list(u1= list(
 
 
 
-sim_all()
+rbook <- sim_all()
 
 
 
-- 
GitLab