Commit 3bf3353e authored by fc-ibb105's avatar fc-ibb105
Browse files

modified utilities.R in R

parent 651951f3
Loading
Loading
Loading
Loading
+36 −0
Original line number Diff line number Diff line
@@ -163,3 +163,39 @@ pdf2 <- function(
		width = width
	)
}

chaos.ext <- function(
				file
){
	file |> 
	strsplit(split = ".",fixed = T) |>
	unlist() |>
	last() |>
	tolower()
}

readRDSMC <-	function(
					file,
					cores = parallel::detectCores()
){
	con <- pipe(paste0("xz -T",cores," -d -k -c ", file))
	object <- tryCatch(
				{readRDS(file = con)},
				error = function(err)
				{
					stop("could not read file\n", file, ":\n", err)
				},
				finally = {if(exists("con")) close(con)}
			)
	return(object)
}

saveRDSMC <-	function(
					object,
					file,
					threads=parallel::detectCores()
){
	con <- pipe(paste0("xz -T", threads, " > ", file), "wb")
	saveRDS(object, file = con)
	on.exit(if(exists("con")) close(con))
}
 No newline at end of file