Skip to content

Commit

Permalink
Adding detected OS and language as DF attributes - adresses #17
Browse files Browse the repository at this point in the history
  • Loading branch information
JuKo007 committed Mar 19, 2024
1 parent 2274156 commit d4f97ac
Show file tree
Hide file tree
Showing 25 changed files with 89 additions and 25 deletions.
6 changes: 6 additions & 0 deletions R/parse_chat.R
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,12 @@ parse_chat <- function(path,
# add them
DF <- cbind.data.frame(DF, TimeOrder, DisplayOrder)

# adding attributes
attributes(DF) <- c(attributes(DF),
parsedAt = as.POSIXct(Sys.time()),
language = language,
detectedOS = os)

# return datframe
return(DF)

Expand Down
2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ pandoc: 3.1.1
pkgdown: 2.0.7
pkgdown_sha: ~
articles: {}
last_built: 2024-02-16T10:00Z
last_built: 2024-03-19T18:38Z

Binary file modified docs/reference/plot_locations-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/plot_locations-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified inst/EnglishAndroid24H_default.rds
Binary file not shown.
Binary file modified inst/EnglishAndroidAMPM_default.rds
Binary file not shown.
Binary file modified inst/EnglishIos24H_default.rds
Binary file not shown.
Binary file modified inst/EnglishIosAMPM_default.rds
Binary file not shown.
Binary file modified inst/GermanAndroid24H_default.rds
Binary file not shown.
Binary file modified inst/GermanAndroidAMPM_default.rds
Binary file not shown.
Binary file modified inst/GermanIos24H_default.rds
Binary file not shown.
Binary file modified inst/GermanIosAMPM_default.rds
Binary file not shown.
Binary file modified inst/TailoredData1.rds
Binary file not shown.
Binary file modified inst/TailoredData2.rds
Binary file not shown.
Binary file modified inst/TailoredData3.rds
Binary file not shown.
Binary file modified inst/TailoredData4.rds
Binary file not shown.
Binary file modified inst/test_lediplo1.rds
Binary file not shown.
Binary file modified inst/test_lediplo2.rds
Binary file not shown.
Binary file modified inst/test_lediplo3.rds
Binary file not shown.
Binary file modified inst/test_lediplo4.rds
Binary file not shown.
Binary file modified inst/test_tokens1.rds
Binary file not shown.
Binary file modified inst/test_tokens2.rds
Binary file not shown.
Binary file modified inst/test_tokens3.rds
Binary file not shown.
Binary file modified inst/test_tokens4.rds
Binary file not shown.
106 changes: 82 additions & 24 deletions tests/testthat/test-WhatsR-tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,13 @@ test_that("Parsing Chatlogs: German, Android, 24h; default", {

# load and check file
test <- readRDS(system.file("GermanAndroid24H_default.rds", package = "WhatsR"))
expect_identical(hush(parse_chat(system.file("germanandroid24h.txt", package = "WhatsR"))), test)
attributes(test) <- attributes(test)[-c(4)]

testfile <- hush(parse_chat(system.file("germanandroid24h.txt", package = "WhatsR")))
attributes(testfile) <- attributes(testfile)[-c(4)]

# checking
expect_identical(testfile, test)
})

test_that("Parsing Chatlogs: German, Ios, 24h; default", {
Expand All @@ -268,8 +274,16 @@ test_that("Parsing Chatlogs: German, Ios, 24h; default", {
# test <- parse_chat(system.file("germanios24h.txt", package = "WhatsR"), anonymize = "add")
# saveRDS(test,"GermanIos24H_default.rds", version = 2)


# load and check file
test <- readRDS(system.file("GermanIos24H_default.rds", package = "WhatsR"))
expect_identical(hush(parse_chat(system.file("germanios24h.txt", package = "WhatsR"))), test)
attributes(test) <- attributes(test)[-c(4)]

testfile <- hush(parse_chat(system.file("germanios24h.txt", package = "WhatsR")))
attributes(testfile) <- attributes(testfile)[-c(4)]

# checking
expect_identical(testfile, test)
})

test_that("Parsing Chatlogs: English, Android, 24h; default", {
Expand All @@ -291,8 +305,15 @@ test_that("Parsing Chatlogs: English, Android, 24h; default", {
# test <- parse_chat(system.file("englishandroid24h.txt", package = "WhatsR"), anonymize = "add")
# saveRDS(test,"EnglishAndroid24H_default.rds", version = 2)

# load and check file
test <- readRDS(system.file("EnglishAndroid24H_default.rds", package = "WhatsR"))
expect_identical(hush(parse_chat(system.file("englishandroid24h.txt", package = "WhatsR"))), test)
attributes(test) <- attributes(test)[-c(4)]

testfile <- hush(parse_chat(system.file("englishandroid24h.txt", package = "WhatsR")))
attributes(testfile) <- attributes(testfile)[-c(4)]

# checking
expect_identical(testfile, test)
})

test_that("Parsing Chatlogs: English, ios, 24h; default", {
Expand All @@ -314,8 +335,15 @@ test_that("Parsing Chatlogs: English, ios, 24h; default", {
# test <- parse_chat(system.file("englishios24h.txt", package = "WhatsR"), anonymize = "add")
# saveRDS(test,"EnglishIos24H_default.rds", version = 2)

# load and check file
test <- readRDS(system.file("EnglishIos24H_default.rds", package = "WhatsR"))
expect_identical(hush(parse_chat(system.file("englishios24h.txt", package = "WhatsR"))), test)
attributes(test) <- attributes(test)[-c(4)]

testfile <- hush(parse_chat(system.file("englishios24h.txt", package = "WhatsR")))
attributes(testfile) <- attributes(testfile)[-c(4)]

# checking
expect_identical(testfile, test)

})

Expand All @@ -342,8 +370,15 @@ test_that("Parsing Chatlogs: German, Android, ampm; default", {
# test <- parse_chat(system.file("germanandroidampm.txt", package = "WhatsR"), anonymize = "add")
# saveRDS(test,"GermanAndroidAMPM_default.rds", version = 2)

# load and check file
test <- readRDS(system.file("GermanAndroidAMPM_default.rds", package = "WhatsR"))
expect_identical(hush(parse_chat(system.file("germanandroidampm.txt", package = "WhatsR"))), test)
attributes(test) <- attributes(test)[-c(4)]

testfile <- hush(parse_chat(system.file("germanandroidampm.txt", package = "WhatsR")))
attributes(testfile) <- attributes(testfile)[-c(4)]

# checking
expect_identical(testfile, test)
})

test_that("Parsing Chatlogs: German, Ios, ampm; default", {
Expand All @@ -365,8 +400,15 @@ test_that("Parsing Chatlogs: German, Ios, ampm; default", {
# test <- parse_chat(system.file("germaniosampm.txt", package = "WhatsR"), anonymize = "add")
# saveRDS(test,"GermanIosAMPM_default.rds", version = 2)

# load and check file
test <- readRDS(system.file("GermanIosAMPM_default.rds", package = "WhatsR"))
expect_identical(hush(parse_chat(system.file("germaniosampm.txt", package = "WhatsR"))), test)
attributes(test) <- attributes(test)[-c(4)]

testfile <- hush(parse_chat(system.file("germaniosampm.txt", package = "WhatsR")))
attributes(testfile) <- attributes(testfile)[-c(4)]

# checking
expect_identical(testfile, test)
})

test_that("Parsing Chatlogs: English, Android, ampm; default", {
Expand All @@ -388,8 +430,15 @@ test_that("Parsing Chatlogs: English, Android, ampm; default", {
# test <- parse_chat(system.file("englishandroidampm.txt", package = "WhatsR"), anonymize = "add")
# saveRDS(test,"EnglishAndroidAMPM_default.rds", version = 2)

# load and check file
test <- readRDS(system.file("EnglishAndroidAMPM_default.rds", package = "WhatsR"))
expect_identical(hush(parse_chat(system.file("englishandroidampm.txt", package = "WhatsR"))), test)
attributes(test) <- attributes(test)[-c(4)]

testfile <- hush(parse_chat(system.file("englishandroidampm.txt", package = "WhatsR")))
attributes(testfile) <- attributes(testfile)[-c(4)]

# checking
expect_identical(testfile, test)
})

test_that("Parsing Chatlogs: English, Ios, ampm; default", {
Expand All @@ -411,9 +460,15 @@ test_that("Parsing Chatlogs: English, Ios, ampm; default", {
# test <- parse_chat(system.file("englishiosampm.txt", package = "WhatsR"), anonymize = "add")
# saveRDS(test,"EnglishIosAMPM_default.rds", version = 2)

# Problem with start_newline
test <- readRDS(system.file("EnglishIosAMPM_default.rds", package = "WhatsR"),)
expect_identical(hush(parse_chat(system.file("englishiosampm.txt", package = "WhatsR"))), test)
# load and check file
test <- readRDS(system.file("EnglishIosAMPM_default.rds", package = "WhatsR"))
attributes(test) <- attributes(test)[-c(4)]

testfile <- hush(parse_chat(system.file("englishiosampm.txt", package = "WhatsR")))
attributes(testfile) <- attributes(testfile)[-c(4)]

# checking
expect_identical(testfile, test)
})


Expand Down Expand Up @@ -972,6 +1027,7 @@ test_that("tailoring function", {
}

data <- parse_chat(system.file("englishiosampm.txt", package = "WhatsR"), anonymize = "add")
attributes(data) <- attributes(data)[-c(4)]

tailored_data1 <- tailor_chat(data,
names = c("Mallory", "Alice"),
Expand All @@ -981,7 +1037,7 @@ test_that("tailoring function", {
)

# generate and write file [Use this to recreate test files when parse_chat() changed]
#saveRDS(tailored_data1,"TailoredData1.rds",version = 2)
# saveRDS(tailored_data1,"TailoredData1.rds",version = 2)

test <- readRDS(system.file("TailoredData1.rds", package = "WhatsR"))
expect_identical(tailored_data1,test)
Expand All @@ -994,7 +1050,7 @@ test_that("tailoring function", {
)

# generate and write file [Use this to recreate test files when parse_chat() changed]
#saveRDS(tailored_data2,"TailoredData2.rds",version = 2)
# saveRDS(tailored_data2,"TailoredData2.rds",version = 2)

test <- readRDS(system.file("TailoredData2.rds", package = "WhatsR"))
expect_identical(tailored_data2,test)
Expand All @@ -1007,7 +1063,7 @@ test_that("tailoring function", {
)

# generate and write file [Use this to recreate test files when parse_chat() changed]
#saveRDS(tailored_data3,"TailoredData3.rds",version = 2)
# saveRDS(tailored_data3,"TailoredData3.rds",version = 2)

test <- readRDS(system.file("TailoredData3.rds", package = "WhatsR"))
expect_identical(tailored_data3,test)
Expand Down Expand Up @@ -1612,6 +1668,7 @@ test_that("Plotting tokens", {
}

data <- parse_chat(system.file("englishiosampm.txt", package = "WhatsR"))
attributes(data) <- attributes(data)[-c(4)]

test_tokens1 <- plot_tokens(data,
names = "all",
Expand All @@ -1623,10 +1680,10 @@ test_that("Plotting tokens", {
)

# generate and write file [Use this to recreate test files when parse_chat() changed]
#saveRDS(test_tokens1,"test_tokens1.rds",version = 2)
# saveRDS(test_tokens1,"test_tokens1.rds",version = 2)

test <- readRDS(system.file("test_tokens1.rds", package = "WhatsR"))
#expect_identical(test_tokens1, test)
# expect_identical(test_tokens1, test)

test_tokens2 <- plot_tokens(data,
names = "all",
Expand All @@ -1638,10 +1695,10 @@ test_that("Plotting tokens", {
)

# generate and write file [Use this to recreate test files when parse_chat() changed]
#saveRDS(test_tokens2,"test_tokens2.rds",version = 2)
# saveRDS(test_tokens2,"test_tokens2.rds",version = 2)

test <- readRDS(system.file("test_tokens2.rds", package = "WhatsR"))
#expect_identical(test_tokens2, test)
# expect_identical(test_tokens2, test)


test_tokens3 <- plot_tokens(data,
Expand All @@ -1654,10 +1711,10 @@ test_that("Plotting tokens", {
)

# generate and write file [Use this to recreate test files when parse_chat() changed]
#saveRDS(test_tokens3,"test_tokens3.rds",version = 2)
# saveRDS(test_tokens3,"test_tokens3.rds",version = 2)

test <- readRDS(system.file("test_tokens3.rds", package = "WhatsR"))
#expect_identical(test_tokens3, test)
# expect_identical(test_tokens3, test)


test_tokens4 <- plot_tokens(data,
Expand All @@ -1670,7 +1727,7 @@ test_that("Plotting tokens", {
)

# generate and write file [Use this to recreate test files when parse_chat() changed]
#saveRDS(test_tokens4,"test_tokens4.rds",version = 2)
# saveRDS(test_tokens4,"test_tokens4.rds",version = 2)

test <- readRDS(system.file("test_tokens4.rds", package = "WhatsR"))
expect_identical(test_tokens4, test)
Expand Down Expand Up @@ -2047,6 +2104,7 @@ test_that("Plotting Lexical Dispersion", {
}

data <- parse_chat(system.file("englishiosampm.txt", package = "WhatsR"))
attributes(data) <- attributes(data)[-c(4)]

test_lediplo1 <- plot_lexical_dispersion(data,
names = "all",
Expand All @@ -2057,7 +2115,7 @@ test_that("Plotting Lexical Dispersion", {
exclude_sm = TRUE
)
# generate and write file [Use this to recreate test files when parse_chat() changed]
#saveRDS(test_lediplo1,"test_lediplo1.rds",version = 2)
# saveRDS(test_lediplo1,"test_lediplo1.rds",version = 2)

test <- readRDS(system.file("test_lediplo1.rds", package = "WhatsR"))
expect_identical(test_lediplo1, test)
Expand All @@ -2073,7 +2131,7 @@ test_that("Plotting Lexical Dispersion", {
)

# generate and write file [Use this to recreate test files when parse_chat() changed]
#saveRDS(test_lediplo2,"test_lediplo2.rds",version = 2)
# saveRDS(test_lediplo2,"test_lediplo2.rds",version = 2)

test <- readRDS(system.file("test_lediplo2.rds", package = "WhatsR"))
expect_identical(test_lediplo2, test)
Expand All @@ -2089,7 +2147,7 @@ test_that("Plotting Lexical Dispersion", {
)

# generate and write file [Use this to recreate test files when parse_chat() changed]
#saveRDS(test_lediplo3,"test_lediplo3.rds",version = 2)
# saveRDS(test_lediplo3,"test_lediplo3.rds",version = 2)


test <- readRDS(system.file("test_lediplo3.rds", package = "WhatsR"))
Expand All @@ -2105,7 +2163,7 @@ test_that("Plotting Lexical Dispersion", {
)

# generate and write file [Use this to recreate test files when parse_chat() changed]
#saveRDS(test_lediplo4,"test_lediplo4.rds",version = 2)
# saveRDS(test_lediplo4,"test_lediplo4.rds",version = 2)


test <- readRDS(system.file("test_lediplo4.rds", package = "WhatsR"))
Expand Down

0 comments on commit d4f97ac

Please sign in to comment.