Skip to content

Commit

Permalink
add rio
Browse files Browse the repository at this point in the history
support csv, fst, rda, rds
  • Loading branch information
kongdd committed Apr 10, 2023
1 parent 309d46b commit e8ea682
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 21 deletions.
5 changes: 2 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@ Imports:
magrittr,
purrr, progress,
lubridate,
data.table,
data.table, fst,
openxlsx,
readxl,
graphics,
methods,
parallel,
doParallel,
foreach, iterators,
plyr,
dplyr,
plyr, dplyr,
clipr, glue,
matrixStats,
rstudioapi,
Expand Down
7 changes: 7 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export("%<>%")
export("%>%")
export("%do%")
export("%dopar%")
export("%||%")
export(.)
export(InitCluster)
export(OS_type)
Expand Down Expand Up @@ -63,6 +64,7 @@ export(edit_r_environ)
export(edit_r_profile)
export(edit_r_profile_sys)
export(evince)
export(export)
export(file_ext)
export(file_mv)
export(file_name)
Expand All @@ -88,6 +90,7 @@ export(group_apply)
export(guess_names)
export(icount)
export(ifelse2)
export(import)
export(install_git)
export(install_gitee)
export(install_github)
Expand Down Expand Up @@ -220,6 +223,8 @@ importFrom(dplyr,tribble)
importFrom(foreach,"%do%")
importFrom(foreach,"%dopar%")
importFrom(foreach,foreach)
importFrom(fst,read_fst)
importFrom(fst,write_fst)
importFrom(grDevices,cairo_pdf)
importFrom(grDevices,col2rgb)
importFrom(grDevices,colorRampPalette)
Expand Down Expand Up @@ -270,8 +275,10 @@ importFrom(plyr,progress_none)
importFrom(plyr,quickdf)
importFrom(plyr,rbind.fill.matrix)
importFrom(plyr,revalue)
importFrom(purrr,`%||%`)
importFrom(purrr,as_mapper)
importFrom(purrr,map)
importFrom(purrr,map_depth)
importFrom(purrr,transpose)
importFrom(remotes,install_git)
importFrom(remotes,install_github)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

- fix `cdo_grid` corner coordinate error.
- set `kill=FALSE` as default in `InitCluster`
- Please manually add `C:/Program Files/RStudio/resources/app/bin/sumatra/SumatraPDF.exe` to your system path
- add rio: support csv, fst, rda, rds

# Ipaper 0.1.7

Expand Down
4 changes: 3 additions & 1 deletion R/cmd_func.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ pdf_view <- function(file, ...) {

#' @rdname pdf_view
#' @export
SumatraPDF <- cmd_func("C:/Program Files/RStudio/resources/app/bin/sumatra/SumatraPDF.exe")
SumatraPDF <- cmd_func("SumatraPDF.exe")

# C:/Program Files/RStudio/resources/app/bin/sumatra/SumatraPDF.exe

#' @rdname pdf_view
#' @export
Expand Down
34 changes: 19 additions & 15 deletions R/reexports.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
#' @export
transpose <- purrr::transpose

#' @importFrom purrr map map_depth `%||%`
#' @export
purrr::`%||%`

#' @export
purrr::map
# #' @importFrom progress progress_bar
# map <- function(.x, .f, ...) {
# n = length(.x)
# pb <- progress_bar$new(total = n)
# .f <- as_mapper(.f, ...)
# .f2 = function(..., .x = ..1, .y = ..2, . = ..1) {
# pb$tick()
# .f(..., .x, .y, .)
# }
# # browser()
# .Call(purrr:::map_impl, environment(), ".x", ".f2", "list")
# }

#' @importFrom plyr mapvalues revalue
#' @export
plyr::mapvalues
Expand All @@ -14,7 +33,6 @@ plyr::revalue

# #' @export
# dplyr::last

first <- function(x) {
x[1]
}
Expand Down Expand Up @@ -57,20 +75,6 @@ magrittr::`%<>%`
#' @export
magrittr::set_names

#' @export
purrr::map
# #' @importFrom progress progress_bar
# map <- function(.x, .f, ...) {
# n = length(.x)
# pb <- progress_bar$new(total = n)
# .f <- as_mapper(.f, ...)
# .f2 = function(..., .x = ..1, .y = ..2, . = ..1) {
# pb$tick()
# .f(..., .x, .y, .)
# }
# # browser()
# .Call(purrr:::map_impl, environment(), ".x", ".f2", "list")
# }

#' @importFrom data.table data.table is.data.table as.data.table fread fwrite
#' @export
Expand Down
38 changes: 38 additions & 0 deletions R/rio.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#' @importFrom fst write_fst read_fst
export_fst <- function(x, path, compress = 100, uniform_encoding = TRUE) {
write_fst(x, path, compress, uniform_encoding)
}

import_fst <- function(
path, columns = NULL, from = 1, to = NULL,
as.data.table = TRUE, old_format = FALSE) {
read_fst(path, columns, from, to, as.data.table, old_format)
}

#' @export
export <- function(x, path) {
ext <- tools::file_ext(path) %>% tolower()
if (ext == "rda") {
save(x, file = path, ...)
} else if (ext == "rds") {
saveRDS(x, path, ...)
} else if (ext == "fst") {
write_fst(x, path, ...)
} else if (ext == "csv") {
fwrite(x, path, ...)
}
}

#' @export
import <- function(path, ...) {
ext <- tools::file_ext(path) %>% tolower()
if (ext == "rda") {
load(path)
} else if (ext == "rds") {
readRDS(path)
} else if (ext == "fst") {
import_fst(path, ...)
} else if (ext == "csv") {
fread(x, path, ...)
}
}
5 changes: 3 additions & 2 deletions man/reexports.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions vignettes/parallel.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
title: "parallel"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{parallel}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```

```{r setup, eval=FALSE}
library(Ipaper)
InitCluster(4)
cl = getOption("cl")
```

```{r, eval=FALSE}
library(parallel)
# 加载共享函数
clusterEvalQ(cl, {
library(Ipaper)
})
# parallel::clusterExport(cl, )
foreach(i = icount(10)) %dopar% {
runningId(i)
}
```

0 comments on commit e8ea682

Please sign in to comment.