Skip to content

Commit 88b72fc

Browse files
committed
r api 2.00.11.1 release
1 parent 1de6c02 commit 88b72fc

39 files changed

+2003
-100
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: RDolphinDB
22
Type: Package
33
Title: Connecting to DolphinDB server with R
4-
Version: 2.0.11.0
5-
Date: 2024-01-29
4+
Version: 2.0.11.1
5+
Date: 2024-03-19
66
Author: mrDrivingDuck
77
Maintainer: mrDrivingDuck <jingtang.zhang@dolphindb.com>
88
Description: The R API of DolphinDB.

R/RDolphinDB.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ setMethod(
187187
DDB_UploadEntity(args)
188188
# Get status
189189
res_stat <- ReceiveHeader()
190+
Clear()
190191
return (res_stat)
191192
}
192193
)
@@ -210,6 +211,7 @@ setMethod(
210211
function(conn) {
211212
DisConnect()
212213
conn@connected <- FALSE
214+
return (conn)
213215
}
214216
)
215217

R/RDolphinDB_impl.R

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ DDB_GetEntity <- function(xxdb_type) {
9090
} else if (xxdb_type == 1) {
9191
# Scalar Logical
9292
if (ReturnScalarNA()) {
93-
result <- NA
93+
result <- as.logical(NA)
9494
} else {
9595
result <- ReturnScalarBool()
9696
}
@@ -100,7 +100,7 @@ DDB_GetEntity <- function(xxdb_type) {
100100
} else if (xxdb_type == 2) {
101101
# Scalar Integer
102102
if (ReturnScalarNA()) {
103-
result <- NA
103+
result <- as.integer(NA)
104104
} else {
105105
result <- ReturnScalarInt()
106106
}
@@ -110,7 +110,7 @@ DDB_GetEntity <- function(xxdb_type) {
110110
} else if (xxdb_type == 3) {
111111
# Scalar Numeric
112112
if (ReturnScalarNA()) {
113-
result <- NA
113+
result <- as.numeric(NA)
114114
} else {
115115
result <- ReturnScalarDouble()
116116
}
@@ -120,7 +120,7 @@ DDB_GetEntity <- function(xxdb_type) {
120120
} else if (xxdb_type == 4) {
121121
# Scalar Character
122122
if (ReturnScalarNA()) {
123-
result <- NA
123+
result <- as.character(NA)
124124
} else {
125125
result <- ReturnScalarString()
126126
}
@@ -130,7 +130,7 @@ DDB_GetEntity <- function(xxdb_type) {
130130
} else if (xxdb_type == 14) {
131131
# Scalar Date
132132
if (ReturnScalarNA()) {
133-
result <- NA
133+
result <- as.Date(NA)
134134
} else {
135135
result <- ReturnScalarDate()
136136
}
@@ -140,7 +140,7 @@ DDB_GetEntity <- function(xxdb_type) {
140140
} else if (xxdb_type == 15) {
141141
# Scalar DateTime
142142
if (ReturnScalarNA()) {
143-
result <- NA
143+
result <- as.POSIXct(NA)
144144
} else {
145145
result <- ReturnScalarTime()
146146
}
@@ -157,6 +157,7 @@ DDB_GetEntity <- function(xxdb_type) {
157157
} else if (xxdb_type == 6) {
158158
# Integer Vector
159159
result <- ReturnVectorInt()
160+
result <- DDB_SetReceiveVectorNA(result, ReturnVectorNAIndex())
160161
Clear()
161162
return (result)
162163

@@ -199,6 +200,7 @@ DDB_GetEntity <- function(xxdb_type) {
199200
} else if (xxdb_type == 10) {
200201
# Integer Matrix
201202
result <- ReturnMatrixInt()
203+
result <- DDB_SetReceiveVectorNA(result, ReturnMatrixNAIndex())
202204
result <- DDB_ReceiveMatrixLable(result)
203205
Clear()
204206
return (result)
@@ -282,7 +284,7 @@ DDB_GetEntity <- function(xxdb_type) {
282284
}
283285

284286
result <- result[,-1]
285-
if(class(result) != "data.frame"){
287+
if(class(result)[1] != "data.frame"){
286288
# if the result only contains one column, then must convert it to dataFrame Explicitly, or it will be a vecor
287289
result = data.frame(result)
288290
}
@@ -294,8 +296,12 @@ DDB_GetEntity <- function(xxdb_type) {
294296
# AnyVector => list
295297
anyVector <- list()
296298
anytypelist <- ReturnAnyVectorTypelist()
297-
298-
for (i in 1:length(anytypelist)) {
299+
len = length(anytypelist)
300+
if(len == 0){
301+
Clear()
302+
return (anyVector)
303+
}
304+
for (i in 1:len) {
299305
if (anytypelist[i] == 0) {
300306
# void
301307
result <- NA
@@ -487,22 +493,20 @@ DDB_GetEntity <- function(xxdb_type) {
487493
# call different C++ functions to upload
488494
# different types of R objects.
489495
DDB_UploadScalar <- function(scl) {
490-
if (is.na(scl) || is.nan(scl)) {
496+
if (is.integer(scl)) {
497+
UploadScalarInt(scl)
498+
}
499+
else if (is.numeric(scl)) {
500+
UploadScalarDouble(scl)
501+
}
502+
else if (is.na(scl)) {
491503

492504
UploadScalarNULL()
493505

494506
} else if (is.logical(scl)) {
495507

496508
UploadScalarBool(scl)
497509

498-
} else if (is.integer(scl)) {
499-
500-
UploadScalarInt(scl)
501-
502-
} else if (is.numeric(scl)) {
503-
504-
UploadScalarDouble(scl)
505-
506510
} else if (is.character(scl)) {
507511

508512
UploadScalarString(scl)
@@ -572,7 +576,7 @@ DDB_UploadVector <- function(vec) {
572576
NAIndex <- DDB_SetUploadVectorNA(vec)
573577
UploadVectorDouble(vec, NAIndex)
574578

575-
} else if (is.character(vec) || class(vec) == "factor") {
579+
} else if (is.character(vec) || is.factor(vec)) {
576580

577581
NAIndex <- DDB_SetUploadVectorNA(vec)
578582
UploadVectorString(vec, NAIndex)
@@ -583,7 +587,7 @@ DDB_UploadVector <- function(vec) {
583587
NAIndex <- DDB_SetUploadVectorNA(vec)
584588
UploadVectorDateTime(vec, NAIndex)
585589

586-
} else if (class(vec) == "Date") {
590+
} else if (inherits(vec, "Date")) {
587591
NAIndex <- DDB_SetUploadVectorNA(vec)
588592
UploadVectorDate(vec, NAIndex)
589593

@@ -615,7 +619,7 @@ DDB_UploadMatrixLable <- function(mtx) {
615619
DDB_UploadVector(rownames(mtx))
616620
}
617621
if (is.null(colnames(mtx)) == FALSE) {
618-
DDB_UploadVector(rownames(mtx))
622+
DDB_UploadVector(colnames(mtx))
619623
}
620624
}
621625

@@ -683,13 +687,13 @@ DDB_UploadObjectCheck <- function(args) {
683687

684688
} else if (is.vector(args[[i]]) && length(args[[i]]) == 1) {
685689

686-
} else if (class(args[[i]]) == "Date" && length(args[[i]]) == 1) {
690+
} else if (class(args[[i]])[1] == "Date" && length(args[[i]]) == 1) {
687691

688-
} else if (class(args[[i]]) == "Date" && length(args[[i]]) > 1) {
692+
} else if (class(args[[i]])[1] == "Date" && length(args[[i]]) > 1) {
689693

690-
} else if (class(args[[i]]) == c("POSIXct", "POSIXt") && length(args[[i]]) == 1) {
694+
} else if (class(args[[i]])[1] == "POSIXct" && length(args[[i]]) == 1) {
691695

692-
} else if (class(args[[i]]) == c("POSIXct", "POSIXt") && length(args[[i]]) > 1) {
696+
} else if (class(args[[i]])[1] == "POSIXct" && length(args[[i]]) > 1) {
693697

694698
} else {
695699
print("Data form not support yet.")
@@ -715,9 +719,20 @@ DDB_UploadEntity <- function(args) {
715719
} else if (is.vector(args[[i]]) && length(args[[i]]) == 1) {
716720
DDB_UploadScalar(args[[i]])
717721
} else if (length(class(args[[i]])) == 2 && class(args[[i]])[1] == "POSIXct") {
718-
DDB_UploadVectorDateTime(args[[i]])
722+
if(length(args[[i]]) == 1){
723+
DDB_UploadScalarDateTime(args[[i]])
724+
}
725+
else{
726+
DDB_UploadVectorDateTime(args[[i]])
727+
}
728+
719729
} else if (class(args[[i]]) == "Date") {
720-
DDB_UploadVectorDate(args[[i]])
730+
if(length(args[[i]]) == 1){
731+
DDB_UploadScalarDate(args[[i]])
732+
}
733+
else{
734+
DDB_UploadVectorDate(args[[i]])
735+
}
721736
} else {
722737
print("Data form not support yet")
723738
Clear()

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ if (conn@connected) {
7575
}
7676
dbClose(conn)
7777
```
78-
7978
### 3. Supported Data Types
8079

8180
R API supports the following data types of DolphinDB:

README_CN.md

Lines changed: 47 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,59 @@
1-
# R API
1+
# DolphinDB R包
22

3-
DolphinDB 提供了 R API 便于用户通过 R 语言操作 DolphinDB。DolphinDB R API 是由 R 和 C++ 实现的,使用的 C++ 包是 Rcpp。
3+
### 1. 关于DolphinDB R包
44

5-
DolphinDB R API支持以下功能:
5+
#### 1.1 简介
6+
7+
DolphinDB提供了R包,用户可以通过R语言操作DolphinDB。DolphinDB R包是由R和C++实现的,使用的C++包是Rcpp。
8+
9+
DolphinDB R包支持以下功能:
610

711
- 运行脚本
812
- 执行DolphinDB中的函数
913
- 上传变量到DolphinDB
1014

11-
## 依赖
15+
#### 1.2 依赖
1216

1317
- R ( ≥ 3. 2. 0)
1418
- Rcpp ( ≥ 0. 12. 17)
1519

16-
## 安装
20+
### 2. 安装DolphinDB R包
1721

18-
### 准备 R 环境
22+
#### 2.1 准备R环境
1923

2024
- Linux系统:
2125

22-
- 执行 `sudo apt-get install r-base` 安装R
23-
- 或者从 [R官网](https://www.r-project.org/) 手动下载安装
26+
- 执行`sudo apt-get install r-base`安装R
27+
- 或者从[R官网](https://www.r-project.org/)手动下载安装
2428

2529
- Windows系统:
2630

27-
- [R官网](https://www.r-project.org/) 下载并安装 R API和 rtools
31+
-[R官网](https://www.r-project.org/)下载并安装R包和rtools
2832

2933
安装时需要配置好环境变量和路径。
3034

31-
### 进入 R 命令行
35+
#### 2.2 进入R命令行
3236

33-
在终端或命令行中输入 `R` 进入 R 命令行
37+
在终端或命令行中输入`R`进入R命令行
3438

35-
### 安装 devtools
39+
#### 2.3 安装devtools
3640

3741
在R命令行中输入`install.packages("devtools")`,选择最近的镜像下载并安装。
3842

39-
### 通过 devtools 安装 DolphinDB R API
43+
#### 2.4 通过devtools安装DolphinDB R包
4044

41-
在 R 命令行中输入 `devtools::install_github("dolphindb/api-r")`系统自动会下载并安装 DolphinDB R API 以及它所依赖的包
45+
在R命令行中输入`devtools::install_github("dolphindb/api-r")`系统自动会下载并安装DolphinDB R包以及它所依赖的包
4246

43-
如果在 Windows 系统上安装时出现 *Warning in system(cmd) : 'make' not found.* 的错误信息,可以在 R 命令行中执行以下代码。安装完成后,程序包将由 g++ 自动编译和链接。
47+
如果在Windows系统上安装时出现 *Warning in system(cmd) : 'make' not found.* 的错误信息,可以在R命令行中执行以下代码。安装完成后,程序包将由g++自动编译和链接。
4448

4549
```R
4650
Sys.setenv(PATH = paste("*InstallDirectory*/Rtools/bin", Sys.getenv("PATH"), sep=";"))
4751
Sys.setenv(BINPREF = "*InstallDirectory*/Rtools/mingw_64/bin")
4852
```
4953

50-
### 使用DolphinDB R API
54+
#### 2.5 使用DolphinDB R包
5155

52-
假设 DolphinDB 运行在主机名为 localhost,端口号为 8848 的服务器上,我们可以通过以下方式来连接 DolphinDB、上传对象和执行脚本:
56+
假设DolphinDB运行在主机名为localhost,端口号为8848的服务器上,我们可以通过以下方式来连接DolphinDB、上传对象和执行脚本:
5357

5458
```R
5559
library(RDolphinDB)
@@ -64,37 +68,9 @@ if (conn@connected) {
6468
dbClose(conn)
6569
```
6670

71+
### 3. 更多函数介绍
6772

68-
## 数据类型支持一览
69-
70-
R API 支持的 DolphinDB 数据类型如下:
71-
72-
| DolphinDB类型 | DolphinDB中数据示例 | R语言类型 | R语言中数据示例 | 说明 |
73-
|---|---|---|---|---|
74-
| BOOL | false | Logical | FALSE | |
75-
| CHAR | 'A' | Integer | 65 | |
76-
| SHORT | 32 | Integer | 32 | |
77-
| INT | 1 | Integer | 1 | |
78-
| LONG | 100000 | Numeric | 10000 | 因为R的整形最大就是2147483647 |
79-
| DATE | 2013.06.13 | Date | 2013-06-13 | |
80-
| MONTH | 2013.08M | Date | 2013-08-01 | 指定为当月第一天 |
81-
| TIME | 13:30:10.008 | POSIXct | 1970-01-01 13:30:10 | 指定为1970.01.01那天的该时刻 |
82-
| MINUTE | 13:30m | POSIXct | 1970-01-01 13:30:00 | 指定为1970.01.01那天的该时刻 |
83-
| SECOND | 13:30:10 | POSIXct | 1970-01-01 13:30:10 | 指定为1970.01.01那天的该时刻 |
84-
| DATETIME | 2012.06.13T13:30:10 | POSIXct | 2012-06-13 13:30:10 | |
85-
| TIMESTAMP | 2012.06.13T13:30:10.008 | POSIXct | 2012-06-13 13:30:10 | |
86-
| NANOTIME | 13:30:10.008007006 | POSIXct | 1970-01-01 13:30:10 | 指定为1970.01.01那天的该时刻 |
87-
| NANOTIMESTAMP | 2012.06.13T13:30:10.008007006 | POSIXct | 2012-06-13 13:30:10 | |
88-
| FLOAT | 2.1f | Numeric | 2.1 | |
89-
| DOUBLE | 2.1 | Numeric | 2.1 | |
90-
| STRING | “123” | character | “123” | |
91-
| SYMBOL | | 不支持 | | |
92-
| BLOB | | 不支持 | | |
93-
| DATEHOUR | | 不支持 | | |
94-
95-
## 更多函数介绍
96-
97-
在R命令行中执行 `help` 函数可以获取更多 DolphinDB R API 中函数的用法。
73+
在R命令行中执行**help**函数可以获取更多DolphinDB R包中函数的用法。
9874

9975
```R
10076
# About the package
@@ -109,4 +85,27 @@ help("dbUpload")
10985
help("dbClose")
11086
```
11187

112-
更多关于 DolphinDB 内置函数的用法,请参考:[DolphinDB 函数参考](https://docs.dolphindb.cn/zh/funcs/funcs_intro.html)
88+
更多关于DolphinDB内置函数的用法,请参考[DolphinDB用户手册](https://www.dolphindb.cn/cn/help/Chapter13FunctionsandCommands.html)
89+
90+
### 4. R API支持的类型统计
91+
注:R内置的时间类型分为日期(Date)和日期+时间(POSIXct)两种,没有单独时间类型。并且只精确到秒
92+
93+
|DolphinDB类型|DolphinDB数据示例|R语言类型|R语言数据示例|说明|
94+
|:-|:-|:-|:-|:-|
95+
|BOOL|false|Logical|FALSE|
96+
|CHAR|'A'|Integer|65|
97+
|SHORT|32|Integer|32|
98+
|INT|1|Integer|1|
99+
|LONG|100000|Numeric|100000|R的整型最大是2147483647
100+
|DATE|2013.06.13|Date|2013-06-13|
101+
|MONTH|2013.08M|Date|2013-08-01|指定为当月第一天
102+
|TIME|13:30:10.008|POSIXct|1970-01-01 13:30:10|指定为1970.01.01那天的该时刻
103+
|MINUTE|13:30m|POSIXct|1970-01-01 13:30:00|指定为1970.01.01那天的该时刻
104+
|SECOND|13:30:10|POSIXct|1970-01-01 13:30:10|指定为1970.01.01那天的该时刻
105+
|DATETIME|2012.06.13T13:30:10|POSIXct|2012-06-13 13:30:10|
106+
|TIMESTAMP|2012.06.13T13:30:10.008|POSIXct|2012-06-13 13:30:10|
107+
|NANOTIME|13:30:10.008007006|POSIXct|1970-01-01 13:30:10|指定为1970.01.01那天的该时刻
108+
|NANOTIMESTAMP|2012.06.13T13:30:10.008007006|POSIXct|2012-06-13 13:30:10|
109+
|FLOAT|2.1f|Numeric|2.1|
110+
|DOUBLE|2.1|Numeric|2.1|
111+
|STRING|"123"|Character|"123"|

ReleaseNotes.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Release Notes
2+
3+
## 2.00.11.0
4+
5+
### Bug Fixes
6+
7+
- Fixed connection failure on Windows.
8+
- Fixed incorrect display of null values for columns with data types CHAR and SHORT during queries.
9+
- Fixed the issue where STRING data from DolphinDB is converted into factor type instead of character type in R during table queries.
10+
- Fixed the error that occurred when reading tables with only one column.
11+
- Fixed the overflow issue when downloading matrices of NANOTIMESTAMP type on Windows.

ReleaseNotes_CN.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# 版本发布说明
2+
3+
## 2.00.11.0
4+
5+
### 故障修复
6+
7+
- 修复了 Windows 版本下 R API 无法连接 DolphinDB server 的问题
8+
- 修复了表查询时数据类型为 CHAR 和 SHORT 的列的空值显示错误的问题。
9+
- 修复了表查询时数据类型为 STRING 的列未能转换为 R语言的 Character 类型的问题。
10+
- 修复了读取只有一列的表时出错的问题。
11+
- 修复了 Windows 版本 API 下载 NANOTIMESTAMP 类型矩阵数值溢出的问题。

0 commit comments

Comments
 (0)