-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata4led.R
147 lines (104 loc) · 5.32 KB
/
data4led.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
### Build LED data package for use with Math 119
# See data_led_private repo
pacman::p_load(tidyverse, glue, readxl, fs)
pacman::p_load_gh("byuidss/DataPushR")
set.seed(20200313)
## Read in data
### Testing Data
sheet_names <- excel_sheets("../data_led_private/data/DataUsedForAnalysis.xlsx")
dat_list <- sheet_names[c(3,7)] %>% map(~read_xlsx("../data_led_private/data/DataUsedForAnalysis.xlsx", sheet = .x))
led_testing <- dat_list %>%
map(~pivot_longer(.x, -Hours, names_to = "id",
values_to = "percent_intensity")) %>%
bind_rows() %>%
mutate(company = ifelse(str_detect(id, "AAA"), "A", "B"),
id = parse_number(id),
normalized_intensity = percent_intensity,
percent_intensity = 100*normalized_intensity) %>%
select(id, hours = Hours, normalized_intensity, percent_intensity, company)
led_test_details <- list(id = "An id for each LED light measured",
hours = "The number of hours since the first measurement",
normalized_intensity = "The normalized light output based on the first measured intensity of the bulb",
percent_intensity = "The normalized_intensity multiplied by 100",
company = "Either A or B to represent to different company products")
load("../data_led_private/data/LumenData.Rdata")
# dat object from the .Rdata file
### Study data ####
led_study <- dat %>%
select(ID, Hours, Intensity, NI) %>%
rename_all("str_to_lower") %>%
rename(percent_intensity = ni) %>%
mutate(hours = floor(hours)) %>%
group_by(id) %>%
mutate(intensity = intensity + rnorm(n(), mean = 0, sd = .25),
normalized_intensity = intensity / intensity[1],
percent_intensity = normalized_intensity*100,
hours = ifelse(hours < 10, 0, hours)) %>%
ungroup() %>%
filter(hours > 25 | hours < 10) %>%
as_tibble() %>%
mutate(hours = ifelse(hours == 191, 192, hours)) %>%
select(id, hours, intensity, normalized_intensity, percent_intensity)
led_study_details <- list(id = "An id for each LED light measured",
hours = "The number of hours since the first measurement",
intensity = "The lumen output of the bulb. 800 lumens maps to a 60 watt incandescent bulb (https://www.lumens.com/how-tos-and-advice/light-bulb-facts.html)",
normalized_intensity = "The normalized light output based on the first measured intensity of the bulb",
percent_intensity = "The normalized_intensity multiplied by 100")
list_data = list(led_study = led_study, led_testing = led_testing)
#################
#################
#################
#usethis::browse_github_token()
package_name_text <- "data4led"
base_folder <- "../../byuidatascience/"
user <- "byuidatascience"
package_path <- str_c(base_folder, package_name_text)
#### Run to create repo locally and on GitHub. ######
# github_info <- dpr_create_github(user, package_name_text)
#
# package_path <- dpr_create_package(list_data = NULL,
# package_name = package_name_text,
# export_folder = base_folder,
# git_remote = github_info$clone_url)
##### dpr_delete_github(user, package_name_text) ####
####### End create section
github_info <- dpr_info_github(user, package_name_text)
usethis::proj_set(package_path)
dpr_export(led_study, export_folder = path(package_path, "data-raw"),
export_format = c(".csv", ".json", ".xlsx", ".sav", ".dta"))
dpr_export(led_testing, export_folder = path(package_path, "data-raw"),
export_format = c(".csv", ".json", ".xlsx", ".sav", ".dta"))
usethis::use_data(led_study, led_testing, overwrite = TRUE)
dpr_document(led_study, extension = ".md.R", export_folder = usethis::proj_get(),
object_name = "led_study", title = "LED example bulbs of lumen output",
description = "An example data set of LED bulbs based on actual data.",
source = "data_led_private",
var_details = led_study_details)
dpr_document(led_testing, extension = ".md.R", export_folder = usethis::proj_get(),
object_name = "led_testing",
title = "LED example bulbs of lumen output for two products with standard procedure time point measurements",
description = "An example data set of LED bulbs based on actual data.",
source = "data_led_private",
var_details = led_test_details)
dpr_readme(usethis::proj_get(), package_name_text, user)
dpr_write_script(folder_dir = package_path, r_read = "scripts/LED_package.R",
r_folder_write = "data-raw", r_write = str_c(package_name_text, ".R"))
devtools::document(package_path)
dpr_push(folder_dir = package_path, message = "'documentation'", repo_url = NULL)
### Some plots
led_study %>%
ggplot(aes(x = hours, y = percent_intensity)) +
geom_line(aes(group = id), color = "grey", alpha = .25) +
geom_point() +
theme_bw()
led_study %>%
ggplot(aes(x = hours, y = percent_intensity)) +
geom_line(aes(group = id), color = "grey", alpha = .25) +
geom_point() +
theme_bw() +
coord_cartesian(xlim = c(20,30))
led_study %>%
ggplot(aes(x = hours, y = intensity)) +
geom_line(aes(group = id), color = "grey", alpha = .25) +
geom_point() +
theme_bw()