Skip to content

Commit b09702f

Browse files
committed
app_stuff
1 parent bfc094e commit b09702f

14 files changed

Lines changed: 2401 additions & 52 deletions

File tree

.DS_Store

2 KB
Binary file not shown.

.Rhistory

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
AssumptionPlotter::simulate_logistic()

Assumption-Plotter.Rproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Version: 1.0
2+
3+
RestoreWorkspace: Default
4+
SaveWorkspace: Default
5+
AlwaysSaveHistory: Default
6+
7+
EnableCodeIndexing: Yes
8+
UseSpacesForTab: Yes
9+
NumSpacesForTab: 2
10+
Encoding: UTF-8
11+
12+
RnwWeave: Sweave
13+
LaTeX: pdfLaTeX
14+
15+
AutoAppendNewline: Yes
16+
StripTrailingWhitespace: Yes

AssumptionPlotter/DESCRIPTION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@ Imports:
2525
testthat,
2626
usethis
2727
VignetteBuilder: quarto
28+
Depends:
29+
R (>= 3.5)

AssumptionPlotter/NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Generated by roxygen2: do not edit by hand
22

33
export(data_log_plot)
4+
export(run_plotter)
45
export(simulate_logistic)
56
import(ggplot2)
7+
import(shiny)
68
import(testthat)
79
import(usethis)

AssumptionPlotter/R/app.R

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#' Edit dataset to fit plotting
2+
#'
3+
#' @details
4+
#' This function edits the data files (from openESM). Technically, the openesm::get_data function should read the files. However, because the function fails to connect to zenodo, some datasets have been manually saved in the package. To make the plotting smooth, this function cleans the files further for analysis. Load additional datasets, go to the dedicated zenodo webpage from openESM, copy the link for the dataset, and add the dataset manually in the app. If the format is correct, the analysis should still work. Make sure to NOT pick the raw data.
5+
#' @param df The data frame. Note that the df should be in wide format.
6+
#' @param id_col Provide the index for which column the participant ID is in. If there is no participant ID (the data frame is for only one participant), write "none".
7+
#' @param day_col Index number for the column containing the days.
8+
#' @param exp_day Expected days of the study.
9+
#' @param beep_col Index number of the column containing the beeps for the day.
10+
#' @param exp_beep Expected beeps per day.
11+
#' @param variables A vector containing the names of all columns to be analysed. Each variable must be within quotation marks.
12+
#' @import dplyr
13+
#' @returns Creates a data file in the data folder of the package.
14+
#' @examples
15+
#' \dontrun{
16+
#' read_openESM_data("0022_menghini_ts", "https://zenodo.org/records/17347538/files/0022_menghini_ts.tsv?download=1")
17+
#' }
18+
19+
edit_df <- function(df, id_col, day_col, exp_day, beep_col, exp_beep, variables){
20+
21+
missing <- data.frame(
22+
id = c(),
23+
beeps = numeric(),
24+
days = numeric()
25+
)
26+
27+
participants <- unique(df[[id_col]])
28+
29+
for(i in 1:length(participants)){
30+
sub_df <- df[df[[id_col]]==participants[i],]
31+
32+
expected_pairs <- expand.grid(
33+
beeps = 1:exp_beep,
34+
days = 1:exp_day
35+
)
36+
37+
actual_pairs <- data.frame(
38+
beeps = sub_df[[beep_col]],
39+
days = sub_df[[day_col]]
40+
)
41+
miss <- anti_join(expected_pairs, actual_pairs, by = c("beeps", "days"))
42+
43+
add <- data.frame(
44+
id = rep(participants[i], times=nrow(miss)),
45+
days = miss$days,
46+
beeps = miss$beeps
47+
)
48+
49+
missing <- rbind(missing, add)
50+
51+
}
52+
53+
54+
new_df <- data.frame(
55+
ID = df[,id_col],
56+
time = 1:nrow(df),
57+
day = df[,day_col],
58+
beep = df[,beep_col]
59+
)
60+
61+
new_var <- paste0("var_", variables)
62+
63+
for(i in 1:length(new_var)){
64+
new_df[new_var[i]] <- df[[variables[i]]]
65+
}
66+
67+
return(missing)
68+
#return(new_df)
69+
#print(missing)
70+
71+
}
72+
73+
buu <- data.frame(x=1:10, y=letters[1:10])
74+
buu[h[1]] <- 36:45
75+
76+
buu[[h[1]]]
77+
78+
mode(lu[,2:3])

AssumptionPlotter/R/run_app.R

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#' Launch shiny app
2+
#'
3+
#' @import shiny
4+
#' @details
5+
#' Finding and launching the main app for the AssumptionPlotter package.
6+
#'
7+
#' @export
8+
#' @examples
9+
#' run_plotter()
10+
#'
11+
12+
run_plotter <- function(){
13+
app_dir <- system.file("app", package = "AssumptionPlotter")
14+
runApp(app_dir)
15+
}
16+
33.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)