Skip to content

Commit

Permalink
0
Browse files Browse the repository at this point in the history
  • Loading branch information
wanganlin00 committed Nov 7, 2024
1 parent 3cf3ab2 commit bb4fc96
Show file tree
Hide file tree
Showing 116 changed files with 41,577 additions and 29,513 deletions.
50 changes: 26 additions & 24 deletions R_notes_version_0/R_Python.qmd
Original file line number Diff line number Diff line change
@@ -1,29 +1,40 @@
---
execute:
eval: false
---

# R⬌Python {.unnumbered}

## 对象转换

| R | Python | |
|------------------------|-------------------|--------------------------------------------------|
| 单元素向量 | 标量Scalar | `1`、 `1L``TRUE``"foo"` |
| 未命名列表或多元素向量 | List | `c(1.0, 2.0, 3.0)``c(1L, 2L, 3L)` |
| 命名列表 | Dict | `list(a = 1L, b = 2.0)``dict(x = x_data)` |
| Matrix/Array | NumPy ndarray | `matrix(c(1,2,3,4), nrow = 2, ncol = 2)` |
| Data Frame | Pandas DataFrame | `data.frame(x = c(1,2,3), y = c("a", "b", "c"))` |
| Function | Python function | `function(x) x + 1` |
| NULL, TRUE, FALSE | None, True, False | `NULL`, `TRUE`, `ALSE` |
| R | Python ||
|------------------------|------------------------|------------------------|
| 单元素向量 | 标量Scalar | `1`、 `1L``TRUE``"foo"` |
| 未命名列表或多元素向量 | List | `c(1.0, 2.0, 3.0)``c(1L, 2L, 3L)` |
| 命名列表 | Dict | `list(a = 1L, b = 2.0)``dict(x = x_data)` |
| Matrix/Array | NumPy ndarray | `matrix(c(1,2,3,4), nrow = 2, ncol = 2)` |
| Data Frame | Pandas DataFrame | `data.frame(x = c(1,2,3), y = c("a", "b", "c"))` |
| Function | Python function | `function(x) x + 1` |
| NULL, TRUE, FALSE | None, True, False | `NULL`, `TRUE`, `ALSE` |

: Type conversions

### [`reticulate::`](https://rstudio.github.io/reticulate/index.html){.uri}
## [`reticulate::`](https://rstudio.github.io/reticulate/index.html){.uri}

```{r}
#| comment: "#>"
library(reticulate)
#devtools::install_version( "ggmap", version = "3.5.2")
if(!require("tidyverse")) {
utils::install.packages("tidyverse")
library(tidyverse)
}
"R code"
```

```{r}
#| comment: "###>"
"python code"
```

### **R 安装 python 模块**
Expand All @@ -45,7 +56,7 @@ reticulate::repl_python()

### R 调用 Python 模块

```{r}
```{r eval=FALSE}
#| comment: "#>"
# 调用os模块(module)的listdir()函数
os <- reticulate::import("os")
Expand Down Expand Up @@ -197,12 +208,3 @@ py$J
class(py$J)
py$J(2, 3)
```

## 编写 Python 时 rpy2 拥有的互操作性

```{r}
#| comment: "#>"
py_module_available("rpy2")
```

......
8 changes: 6 additions & 2 deletions R_notes_version_0/_quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ project:
output-dir: docs

book:
title: "R 数据科学与编程"
title: "R数据科学与编程"
reader-mode: true
chapters:
- index.qmd
Expand All @@ -25,12 +25,16 @@ book:

- part: "大数据"
chapters:
- big_data.qmd

- data.table.qmd
- arrow.qmd
- polars.qmd
- parallel_computing.qmd
- spark.qmd
- Rcpp.qmd
- R_Python.qmd


- part: "编程"
chapters:
- control_structure.qmd
Expand Down
9 changes: 5 additions & 4 deletions R_notes_version_0/arrow.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

## 安装

[apache-arrow.tar.gz](https://github.com/apache/arrow/releases/tag/apache-arrow-17.0.0)
[apache-arrow.tar.gz](https://github.com/apache/arrow/releases/)

```{r eval=FALSE}
```{r include=FALSE}
options(timeout = 300)
install.packages("arrow")
if(!require(arrow)) install.packages("arrow")
```

read_parquet():读取 Parquet 格式的文件
Expand All @@ -17,4 +18,4 @@ read_delim_arrow():读取带分隔符的文本文件

read_csv_arrow():读取逗号分隔值 (CSV) 文件

read_tsv_arrow():读取制表符分隔值 (TSV) 文件
read_tsv_arrow():读取制表符分隔值 (TSV) 文件
120 changes: 0 additions & 120 deletions R_notes_version_0/big_data.qmd

This file was deleted.

Binary file not shown.
Binary file modified R_notes_version_0/data/read_write/多个sheet-iris_data.xlsx
Binary file not shown.
Loading

0 comments on commit bb4fc96

Please sign in to comment.