Skip to content

Commit 6394fc4

Browse files
committed
Issues #164 and #165 and upgrade version.
1 parent a4babc8 commit 6394fc4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+248
-237
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: libr
22
Type: Package
33
Title: Libraries, Data Dictionaries, and a Data Step for R
4-
Version: 1.3.2
4+
Version: 1.3.3
55
Author: David J. Bosak
66
Maintainer: David Bosak <dbosak01@gmail.com>
77
Description: Contains a set of functions to create data libraries,

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# libr 1.3.3
2+
* Fixed issue where `lib_write()` was not detecting changes to datasets in libname.
3+
14
# libr 1.3.2
25
* Fixed bug on `libname()` when there are file names with multiple dots.
36

R/dictionary.R

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -166,67 +166,4 @@ getDictionary <- function(x, dsnm) {
166166
}
167167

168168

169-
getDictionary_back <- function(x, dsnm) {
170-
171-
ret <- NULL
172-
rw <- NULL
173-
usr_wdth <- c()
174-
str_wdth <- c()
175-
cntr <- 0
176-
177-
for (nm in names(x)) {
178-
179-
180-
181-
cntr <- cntr + 1
182-
183-
lbl <- attr(x[[nm]], "label")
184-
desc <- attr(x[[nm]], "description")
185-
fmt <- paste(as.character(attr(x[[nm]], "format")), collapse = "\n")
186-
jst <- attr(x[[nm]], "justify")
187-
wdth <- attr(x[[nm]], "width")
188-
189-
if (fmt == "")
190-
fmt <- NA
191-
192-
if (is.null(wdth)) {
193-
if (length(x[[nm]]) > 0) {
194-
str_wdth[cntr] <- ifelse(typeof(x[[nm]]) == "character",
195-
max(nchar(x[[nm]])),
196-
NA)
197-
} else {
198-
199-
str_wdth[cntr] <- NA
200-
}
201-
202-
} else {
203-
usr_wdth[cntr] <- wdth
204-
}
205-
206-
rw <- data.frame(Name = dsnm,
207-
Column = nm,
208-
Class = paste0(class(x[[nm]]), collapse = " "),
209-
Label = ifelse(!is.null(lbl), lbl, as.character(NA)),
210-
Description = ifelse(!is.null(desc), desc, as.character(NA)),
211-
Format = ifelse(!is.null(fmt), fmt, NA),
212-
Width = ifelse(!is.null(wdth), wdth, NA),
213-
Justify = ifelse(!is.null(jst), jst, as.character(NA)),
214-
Rows = nrow(x),
215-
NAs = sum(is.na(x[[nm]])))
216-
217-
218-
if (is.null(ret))
219-
ret <- rw
220-
else
221-
ret <- rbind(ret, rw)
222-
223-
}
224-
225-
226-
if (length(usr_wdth) == 0)
227-
ret[["Width"]] <- str_wdth
228-
229-
return(ret)
230-
231-
}
232169

R/libname.R

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,10 @@ libname <- function(name, directory_path, engine = "rds",
510510
attr(dat, "extension") <- ext
511511
attr(dat, "path") <- fp
512512
attr(dat, "checksum") <- md5sum(fp)
513-
513+
sig <- captureSignatures(dat)
514+
attr(dat, "length") <- sig$Length
515+
attr(dat, "hex") <- sig$Hex
516+
514517
l[[nm]] <- dat
515518
}
516519
}
@@ -529,17 +532,19 @@ libname <- function(name, directory_path, engine = "rds",
529532

530533

531534

532-
533535
# Manipulation Functions --------------------------------------------------
534536

535-
536537
#' @title Load a Library into the Workspace
537538
#' @description The \code{lib_load} function loads a data library into
538539
#' an environment. The environment used is associated with the library at
539540
#' the time it is created with the \code{\link{libname}} function.
540541
#' When the \code{lib_load} function is called, the data frames/tibbles
541542
#' will be loaded with <library>.<data set> syntax. Loading the data frames
542543
#' into the environment makes them easy to access and use in your program.
544+
#'
545+
#' Note that the \code{lib_load} function is optional, and calling the function
546+
#' is not needed to access data in the \code{libname}. You may also access
547+
#' data directly from the \code{libname} using the dollar sign ($) syntax.
543548
#' @param x The data library to load.
544549
#' @param filter One or more quoted strings to use as filters for the
545550
#' data names to load into the workspace. For more than one filter string,

R/utilities.R

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,36 @@ writeData <- function(x, ext, file_path, force = FALSE) {
196196
# Compare checksums
197197
cs_comp <- cs1 == cs2
198198

199+
sig <- captureSignatures(x)
200+
201+
# If passes, compare df to file
202+
if (!force && cs_comp == TRUE) {
203+
204+
al <- attr(x, "length")
205+
ah <- attr(x, "hex")
206+
207+
if (!is.null(al)) {
208+
if (sig$Length != al)
209+
cs_comp <- FALSE
210+
}
211+
212+
if (!is.null(ah)) {
213+
214+
if (sig$Hex != ah)
215+
cs_comp <- FALSE
216+
}
217+
}
218+
219+
199220
if (ext == "csv") {
200221

201222
if (!cs_comp | force) {
202223
if (file.exists(file_path))
203224
file.remove(file_path)
204225
write_csv(x, file_path, na = "")
205226
attr(x, "checksum") <- md5sum(file_path)
227+
attr(x, "length") <- sig$Length
228+
attr(x, "hex") <- sig$Hex
206229
}
207230

208231
} else if (ext == "rds") {
@@ -212,6 +235,8 @@ writeData <- function(x, ext, file_path, force = FALSE) {
212235
file.remove(file_path)
213236
write_rds(x, file_path)
214237
attr(x, "checksum") <- md5sum(file_path)
238+
attr(x, "length") <- sig$Length
239+
attr(x, "hex") <- sig$Hex
215240
}
216241

217242
} else if (tolower(ext) %in% c("rdata", "rda")) {
@@ -221,6 +246,8 @@ writeData <- function(x, ext, file_path, force = FALSE) {
221246
file.remove(file_path)
222247
save(x, file = file_path)
223248
attr(x, "checksum") <- md5sum(file_path)
249+
attr(x, "length") <- sig$Length
250+
attr(x, "hex") <- sig$Hex
224251
}
225252

226253
} else if (ext == "sas7bdat") {
@@ -239,6 +266,8 @@ writeData <- function(x, ext, file_path, force = FALSE) {
239266
file.remove(file_path)
240267
foreign::write.dbf(as.data.frame(x, stringsAsFactors = FALSE), file_path)
241268
attr(x, "checksum") <- md5sum(file_path)
269+
attr(x, "length") <- sig$Length
270+
attr(x, "hex") <- sig$Hex
242271
}
243272

244273
} else if (ext == "xpt") {
@@ -248,6 +277,8 @@ writeData <- function(x, ext, file_path, force = FALSE) {
248277
file.remove(file_path)
249278
write_xpt(x, file_path)
250279
attr(x, "checksum") <- md5sum(file_path)
280+
attr(x, "length") <- sig$Length
281+
attr(x, "hex") <- sig$Hex
251282
}
252283

253284
} else if (ext == "xlsx") {
@@ -257,6 +288,8 @@ writeData <- function(x, ext, file_path, force = FALSE) {
257288
file.remove(file_path)
258289
openxlsx::write.xlsx(x, file_path)
259290
attr(x, "checksum") <- md5sum(file_path)
291+
attr(x, "length") <- sig$Length
292+
attr(x, "hex") <- sig$Hex
260293
}
261294

262295
} else if (ext == "xls") {
@@ -272,6 +305,8 @@ writeData <- function(x, ext, file_path, force = FALSE) {
272305
attr(x, "extension") <- "xlsx"
273306
attr(x, "path") <- fp
274307
attr(x, "checksum") <- md5sum(fp)
308+
attr(x, "length") <- sig$Length
309+
attr(x, "hex") <- sig$Hex
275310
}
276311

277312
}
@@ -508,6 +543,37 @@ log_output <- function() {
508543

509544

510545

546+
getBitSignature <- function(x) {
547+
548+
spos <- x[1]
549+
for (i in seq(2, length(x))) {
550+
551+
spos <- xor(spos, x[i])
552+
}
553+
554+
return(spos)
555+
}
556+
557+
558+
captureSignatures <- function(dat) {
559+
560+
ret <- list()
561+
562+
att <- attributes(dat)
563+
for (nm in names(att)) {
564+
if (!nm %in% c("class", "name"))
565+
attr(dat, nm) <- NULL
566+
}
567+
568+
idat <- serialize(dat, connection = NULL)
569+
570+
ret$Length <- length(idat)
571+
ret$Hex <- getBitSignature(idat)
572+
573+
return(ret)
574+
}
575+
576+
511577
# @noRd
512578
# standard_eval <- function() {
513579
#

docs/404.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/articles/index.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/articles/libr-basics.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/articles/libr-datastep.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/articles/libr-disclaimer.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/articles/libr-example1.html

Lines changed: 3 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/articles/libr-example2.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/articles/libr-faq.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/articles/libr-management.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/articles/libr.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/authors.html

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)