-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rhistory
512 lines (512 loc) · 15.2 KB
/
.Rhistory
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
renv::install("curl")
renv::install("foreign")
renv::install("haven")
renv::install("R.util")
renv::install("R.utils")
renv::install("rio")
renv::init()
renv::statu()
renv::status()
renv::snapshot()
devtools::load_all(".")
renv::install("devtools")
devtools::load_all(".")
get_iox("/Users/heverz/Desktop/prova/")
get_iox("/Users/heverz/Desktop/prova/", inter = FALSE)
devtools::load_all(".")
get_iox("/Users/heverz/Desktop/prova/", inter = FALSE)
subj_info <- lapply(
files_imp,
vroom::vroom,
skip = 15,
n_max = 1,
delim = "\t",
col_names = FALSE,
col_select = "X7",
col_types = c(X7 = "c")
)
View(subj_info)
subj_info2 <- lapply(subj_info, function(x) unlist(x)[[1]][1])
subj_info2
subj <- as.numeric(stringr::str_extract(subj_info2, "[[:digit:]]+"))
subj
subj_info2
drug <- gsub("^.*[0-9].*?([[:alpha:]]{4,}).*", "\\1", subj_info2)
drug
subj_drug_v <- paste0("rat", unlist(subj), "_", unlist(drug))
subj_drug_v
get_iox("/Users/heverz/Desktop/prova/", inter = FALSE)
subj_info <- lapply(
files_imp,
vroom::vroom,
skip = 15,
n_max = 1,
delim = "\t",
col_names = FALSE,
col_select = "X7",
col_types = c(X7 = "c")
)
subj_info
devtools::load_all(".")
get_iox("/Users/heverz/Desktop/prova/", inter = FALSE)
subj_info <- lapply(
files_imp,
vroom::vroom,
skip = 15,
n_max = 1,
delim = "\t",
col_names = FALSE,
col_select = "X7",
col_types = c(X7 = "c")
)
subj_info
subj_info2 <- lapply(subj_info, function(x) unlist(x)[[1]][1])
subj_info2
subj <- as.numeric(stringr::str_extract(subj_info2, "[[:digit:]]+"))
drug <- gsub("^.*[0-9].*?([[:alpha:]]{4,}).*", "\\1", subj_info2)
subj_drug_v <- paste0("rat", unlist(subj), "_", unlist(drug))
drug
subj_info2
subj
subj_info2
drug <- gsub("^.*[0-9].*?([[:alpha:]]{3,}).*", "\\1", subj_info2)
drug
get_iox("/Users/heverz/Desktop/prova/", inter = FALSE)
subj_info <- lapply(
files_imp,
vroom::vroom,
skip = 15,
n_max = 1,
delim = "\t",
col_names = FALSE,
col_select = "X7",
col_types = c(X7 = "c")
)
if (shiny_f == TRUE){
if (missing(iox_data) || is.null(iox_data) ) stop("iox files missing!")
files_imp <- dplyr::filter(iox_data, stringr::str_detect(.data$name, pattern = "iox.txt"))
mess <- "You have not selected any iox.txt files!"
if (length(files_imp) == 0) {
stop(mess)
}
# not sure why it appears that files have different columns.
# this is a workaround that extract name and drug form cell 16,7
subj_info <- lapply(
files_imp$datapath,
vroom::vroom,
skip = 15,
n_max = 1,
delim = "\t",
col_names = FALSE,
col_select = "X7",
col_types = c(X7 = "c")
)
} else {
mess <- "Choose folder containing iox.txt files of the session."
if (inter == FALSE) {
if (missing(iox_data)) stop("iox folder missing!")
} else {
svDialogs::dlg_message(mess, type = "ok")
iox_data <- svDialogs::dlg_dir(title = mess)$res
}
list_files <- list.files(iox_data, full.names = TRUE)
files_imp <- list_files[grepl(pattern = "*iox.txt", list_files)]
mess <- "There are not iox.txt files in that folder!"
if (length(files_imp) == 0) {
if (inter == TRUE) {
stop(svDialogs::dlgMessage(mess,
type = "ok"
)$res)
} else {
stop(mess)
}
}
# not sure why it appears that files have different columns.
# this is a workaround that extract name and drug form cell 16,7
browser()
subj_info <- lapply(
files_imp,
vroom::vroom,
skip = 15,
n_max = 1,
delim = "\t",
col_names = FALSE,
col_select = "X7",
col_types = c(X7 = "c")
)
}
get_iox("/Users/heverz/Desktop/prova/", inter = FALSE)
devtools::load_all(".")
devtools::load_all(".")
get_iox("/Users/heverz/Desktop/prova/", inter = FALSE)
devtools::load_all(".")
get_iox("/Users/heverz/Desktop/prova/", inter = FALSE)
# not sure why it appears that files have different columns.
# this is a workaround that extract name and drug form cell 16,7
subj_info <- lapply(
files_imp,
vroom::vroom,
skip = 15,
n_max = 1,
delim = "\t",
col_names = FALSE,
col_select = "X7",
col_types = c(X7 = "c")
)
if (shiny_f == TRUE){
if (missing(iox_data) || is.null(iox_data) ) stop("iox files missing!")
files_imp <- dplyr::filter(iox_data, stringr::str_detect(.data$name, pattern = "iox.txt"))
mess <- "You have not selected any iox.txt files!"
if (length(files_imp) == 0) {
stop(mess)
}
# not sure why it appears that files have different columns.
# this is a workaround that extract name and drug form cell 16,7
subj_info <- lapply(
files_imp$datapath,
vroom::vroom,
skip = 15,
n_max = 1,
delim = "\t",
col_names = FALSE,
col_select = "X7",
col_types = c(X7 = "c")
)
} else {
mess <- "Choose folder containing iox.txt files of the session."
if (inter == FALSE) {
if (missing(iox_data)) stop("iox folder missing!")
} else {
svDialogs::dlg_message(mess, type = "ok")
iox_data <- svDialogs::dlg_dir(title = mess)$res
}
list_files <- list.files(iox_data, full.names = TRUE)
files_imp <- list_files[grepl(pattern = "*iox.txt", list_files)]
mess <- "There are not iox.txt files in that folder!"
if (length(files_imp) == 0) {
if (inter == TRUE) {
stop(svDialogs::dlgMessage(mess,
type = "ok"
)$res)
} else {
stop(mess)
}
}
browser()
# not sure why it appears that files have different columns.
# this is a workaround that extract name and drug form cell 16,7
subj_info <- lapply(
files_imp,
vroom::vroom,
skip = 15,
n_max = 1,
delim = "\t",
col_names = FALSE,
col_select = "X7",
col_types = c(X7 = "c")
)
}
get_iox("/Users/heverz/Desktop/prova/", inter = FALSE)
# not sure why it appears that files have different columns.
# this is a workaround that extract name and drug form cell 16,7
subj_info <- lapply(
files_imp,
vroom::vroom,
skip = 15,
n_max = 1,
delim = "\t",
col_names = FALSE,
col_select = "X7",
col_types = c(X7 = "c")
)
subj_info
subj_info2 <- lapply(subj_info, function(x) unlist(x)[[1]][1])
subj_info2
subj
subj <- as.numeric(stringr::str_extract(subj_info2, "[[:digit:]]+"))
subj
drug <- gsub("^.*[0-9].*?([[:alpha:]]{3,}).*", "\\1", subj_info2)
drug
subj_drug_v <- paste0("rat", unlist(subj), "_", unlist(drug))
subj_drug_v
vent <- vroom::vroom(files_imp,
delim = "\t",
skip = 41,
col_names = FALSE,
col_types = list(
X6 = "c",
X7 = "c",
X8 = "c",
X9 = "c"
),
id = "id"
)
vent
names(vent) <- unlist(iox_head)
vent
names(vent)
# time in seconds from cpu_time, unfortunately the other columns reset to 0 after 1h
# Aug 19, 2019, 19-Mar-19
vent$cpu_date <- lubridate::parse_date_time(vent$cpu_date,
orders = c("%b %d, %Y", "%d-%b-%y")
)
vent <- tidyr::separate(vent, .data$cpu_time, c("cpu_time", "cpu_ms"), sep = "\\.")
vent$cpu_time <- as.POSIXct(vent$cpu_time, format = "%I:%M:%S %p")
vent[, "timecpu_s"] <- as.numeric(vent$cpu_ms) / 1000 +
as.numeric(format(vent$cpu_time, "%S")) +
as.numeric(format(vent$cpu_time, "%M")) * 60 +
as.numeric(format(vent$cpu_time, "%H")) * 3600
# recode \
vent_id <- as.character(unique(vent$id))
vent_id
id_recode <- subj_drug_v[seq_along(vent_id)]
id_recode
newnames <- stats::setNames(id_recode, vent_id)
newnames
vent[, "subj_drug"] <- newnames[vent$id]
View(vent)
vent$subj_drug <- as.factor(newnames[vent$id])
as.factor(newnames[vent$id])
vent$subj_drug
# vent$string_type <-
vent$string_type[is.na(vent$string_type)] <- 0
comments <- stats::na.omit(unique(vent$info[vent$string_type == c("comment")]))
# eliminate comments without subjects (i.e. numbers)
comments <- comments[stringr::str_detect(comments, "[1-9]")]
comments
# tsd = time_injection subject and drug
tsd <- vent[vent$info %in% comments, c("cpu_date", "timecpu_s", "info")]
tsd
tsd$info <- stringr::str_remove_all(tsd$info, "^([:alpha:]{3,4}\\s)|^[:alpha:]{3,4}") # rat rats or ray
tsd$info
# "number number number"
tsd <- split_comments(tsd, detect = "[0-9]\\s[0-9]+", sep = "(?<=[0-9])\\s(?=[A-z])", rem = "")
tsd
tsd$info <- stringr::str_remove_all(tsd$info, "^([:alpha:]{3,4}\\s)|^[:alpha:]{3,4}") # rat rats or ray
tsd$info
vent$info
unique(vent$info)
comments
vent$info %in% comments
# tsd = time_injection subject and drug
tsd <- vent[vent$info %in% comments, c("cpu_date", "timecpu_s", "info")]
tsd
tsd$info <- stringr::str_remove_all(tsd$info, "^([:alpha:]{3,4}\\s)|^[:alpha:]{3,4}") # rat rats or ray
# "number number number"
tsd <- split_comments(tsd, detect = "[0-9]\\s[0-9]+", sep = "(?<=[0-9])\\s(?=[A-z])", rem = "")
devtools::load_all(".")
get_iox("/Users/heverz/Desktop/prova/", inter = FALSE)
tsd
tsd$info <- stringr::str_remove_all(tsd$info, " -") # there are comments with that
tsd
tsd$info <- stringr::str_remove_all(tsd$info, " -") # there are comments with that
tsd$info
toadd <- tsd[stringr::str_detect(tsd$info, detect), ] # get comments with "number number number"
toadd
tsd$info <- stringr::str_remove_all(tsd$info, " -") # there are comments with that
tsd$info
toadd
tsd
View(tsd)
toadd <- tsd[stringr::str_detect(tsd$info, detect), ] # get comments with "number number number"
tsd2 <- dplyr::setdiff(tsd, toadd) # remove them
tsd2
toadd <- tidyr::separate(toadd, .data$info,
sep = sep, c("subj", "info"),
extra = "merge"
) # separate subject from rest: first space between number and word
toadd
n_subj <- unlist(stringr::str_split(unlist(toadd$subj), " ")) # create a vector of subjects
n_subj
j <- unlist(stringr::str_split(unlist(toadd$subj), " ")) # create a vector of subjects
c
rlang::last_trace()
get_iox("/Users/heverz/Desktop/prova/", inter = FALSE)
tsd$info <- stringr::str_remove_all(tsd$info, " -") # there are comments with that
View(tsd)
tsd
View(tsd)
get_iox("./inst/extdata/data1/", inter = FALSE)
force(tsd)
View(tsd)
tsd$info <- stringr::str_remove_all(tsd$info, " -") # there are comments with that
tsd
toadd <- tsd[stringr::str_detect(tsd$info, detect), ] # get comments with "number number number"
toadd
tsd2 <- dplyr::setdiff(tsd, toadd) # remove them
tsd2
toadd
toadd <- tidyr::separate(toadd, .data$info,
sep = sep, c("subj", "info"),
extra = "merge"
) # separate subject from rest: first space between number and word
toadd
n_subj <- unlist(stringr::str_split(unlist(toadd$subj), " ")) # create a vector of subjects
n_subj
col_subj
col_subj <- n_subj[n_subj != rem] # remove and
col_subj
rep_subj <- stringr::str_count(toadd$subj, "[0-9]") # how many subjects in each comment?
rep_subj
toadd <- toadd[rep(seq_len(nrow(toadd)), rep_subj), ] # repeat rows for each subject
toadd
toadd$subj <- col_subj # substitute subject
toadd
tsd3 <- tidyr::separate(tsd2, .data$info,
sep = "(?<=[0-9])\\s", c("subj", "info"),
extra = "merge"
)
tsd3
tsd3
tsd3
tsd3
tsd3
tsd4 <- rbind(tsd3, toadd)
tsd4
devtools::load_all(".")
get_iox("./inst/extdata/data1/", inter = FALSE)
get_iox("./inst/extdata/data1/", inter = FALSE)
tsd
devtools::load_all(".")
devtools::load_all(".")
tsd$subj <- as.numeric(tsd$subj)
devtools::load_all(".")
get_iox("./inst/extdata/data1/", inter = FALSE)
View(tsd)
tsd$subj <- as.numeric(tsd$subj)
tsd <- tidyr::unite(tsd, "info", .data$subj, .data$info, sep = " ")
tsd
# space between a number and a word that is not "and"
tsd <- split_comments(tsd, detect = "and", sep = "(?<=[0-9])\\s(?=[A-z])(?!and)", rem = "and")
tsd
tsd$info <- stringr::str_remove_all(tsd$info, "(?!/)[:punct:]")
tsd
devtools::load_all(".")
get_iox("/Users/heverz/Desktop/prova/", inter = FALSE)
tsd$info
toadd
toadd <- tsd[stringr::str_detect(tsd$info, detect), ] # get comments with "number number number"
toadd
tsd2
tsd
tsd2 <- dplyr::setdiff(tsd, toadd) # remove them
tsd2
toadd <- tidyr::separate(toadd, .data$info,
sep = sep, c("subj", "info"),
extra = "merge"
) # separate subject from rest: first space between number and word
toadd
n_subj <- unlist(stringr::str_split(unlist(toadd$subj), " ")) # create a vector of subjects
n_subj
col_subj
col_subj <- n_subj[n_subj != rem] # remove and
col_subj
rep_subj <- stringr::str_count(toadd$subj, "[0-9]") # how many subjects in each comment?
rep_subj
rep_subj
rep_subj
col_subj
to_add$subj
toadd$subj
rep_subj <- stringr::str_count(toadd$subj, "\\d+") # how many subjects in each comment?
rep_subj
toadd <- toadd[rep(seq_len(nrow(toadd)), rep_subj), ] # repeat rows for each subject
toadd$subj <- col_subj # substitute subject
toadd$subj
tsd3 <- tidyr::separate(tsd2, .data$info,
sep = "(?<=[0-9])\\s", c("subj", "info"),
extra = "merge"
)
tsd3
tsd4 <- rbind(tsd3, toadd)
tsd4
get_iox("/Users/heverz/Desktop/prova/", inter = FALSE)
devtools::load_all(".")
devtools::load_all(".")
get_iox("/Users/heverz/Desktop/prova/", inter = FALSE)
tsd$subj <- as.numeric(tsd$subj)
View(tsd)
# tsd = time_injection subject and drug
tsd <- vent[vent$info %in% comments, c("cpu_date", "timecpu_s", "info")]
tsd$info <- stringr::str_remove_all(tsd$info, "^([:alpha:]{3,4}\\s)|^[:alpha:]{3,4}") # rat rats or ray
# "number number number"
tsd <- split_comments(tsd, detect = "[0-9]\\s[0-9]+", sep = "(?<=[0-9])\\s(?=[A-z])", rem = "")
tsd
subj <- as.numeric(stringr::str_extract(subj_info2, "[[:digit:]]+"))
subj
tsd
tsd
# tsd = time_injection subject and drug
tsd <- vent[vent$info %in% comments, c("cpu_date", "timecpu_s", "info")]
View(tsd)
get_iox("/Users/heverz/Desktop/prova/", inter = FALSE)
devtools::load_all(".")
devtools::load_all(".")
get_iox("/Users/heverz/Desktop/prova/", inter = FALSE)
toadd <- tsd[stringr::str_detect(tsd$info, detect), ] # get comments with "number number number"
tsd2 <- dplyr::setdiff(tsd, toadd) # remove them
View(toadd)
devtools::load_all(".")
get_iox("/Users/heverz/Desktop/prova/", inter = FALSE)
tsd
# tsd = time_injection subject and drug
tsd <- vent[vent$info %in% comments, c("cpu_date", "timecpu_s", "info")]
tsd
tsd$info <- stringr::str_remove_all(tsd$info, "^([:alpha:]{3,4}\\s)|^[:alpha:]{3,4}") # rat rats or ray
# "number number number"
tsd <- split_comments(tsd, detect = "[0-9]\\s[0-9]+", sep = "(?<=[0-9])\\s(?=[A-z])", rem = "")
tsd
devtools::load_all(".")
get_iox("/Users/heverz/Desktop/prova/", inter = FALSE)
tsd$info <- stringr::str_remove_all(tsd$info, " -") # there are comments with that
toadd <- tsd[stringr::str_detect(tsd$info, detect), ] # get comments with "number number number"
tsd2 <- dplyr::setdiff(tsd, toadd) # remove them
toadd <- tidyr::separate(toadd, .data$info,
sep = sep, c("subj", "info"),
extra = "merge"
) # separate subject from rest: first space between number and word
toadd
n_subj <- unlist(stringr::str_split(unlist(toadd$subj), " ")) # create a vector of subjects
n_subj
col_subj <- n_subj[n_subj != rem] # remove
rep_subj <- stringr::str_count(toadd$subj, "\\d+") # how many subjects in each comment?
rep_subj
toadd <- toadd[rep(seq_len(nrow(toadd)), rep_subj), ] # repeat rows for each subject
toadd
toadd$subj <- col_subj # substitute subject
toadd
View(tsd2)
str_replace("07nlx", "\\d+[[:alpha:]]","\\d+\\s[[:alpha:]]" )
stringt::str_replace("07nlx", "\\d+[[:alpha:]]","\\d+\\s[[:alpha:]]" )
stringr::str_replace("07nlx", "\\d+[[:alpha:]]","\\d+\\s[[:alpha:]]" )
gsub("([0-9])([[:alpha:]])", "\\1 \\2", tsd$info)
# add a space if subject and treatment do not have it (e.s. 07nlx)
tsd$info <- gsub("([0-9])([[:alpha:]])", "\\1 \\2", tsd$info)
tsd3 <- tidyr::separate(tsd2, .data$info,
sep = "(?<=[0-9])\\s", c("subj", "info"),
extra = "merge"
)
tsd4 <- rbind(tsd3, toadd)
tsd4
# add a space if subject and treatment do not have it (e.s. 07nlx)
tsd$info <- gsub("([0-9])([[:alpha:]])", "\\1 \\2", tsd$info)
tsd$info
# add a space if subject and treatment do not have it (e.s. 07nlx)
tsd2$info <- gsub("([0-9])([[:alpha:]])", "\\1 \\2", tsd2$info)
tsd3 <- tidyr::separate(tsd2, .data$info,
sep = "(?<=[0-9])\\s", c("subj", "info"),
extra = "merge"
)
tsd3
tsd4 <- rbind(tsd3, toadd)
devtools::load_all(".")
get_iox("/Users/heverz/Desktop/prova/", inter = FALSE)
get_iox("/Users/heverz/Desktop/prova/", inter = FALSE)
devtools::load_all(".")
devtools::load_all(".")
get_iox("/Users/heverz/Desktop/prova/", inter = FALSE)
renv::status()
renv::snapshot()
library(rvent)
43 * 60
42 * 60