Skip to content

Commit a7abb54

Browse files
committed
update
1 parent 394af60 commit a7abb54

19 files changed

+686
-198
lines changed

R/RDolphinDB_impl.R

Lines changed: 52 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,7 @@ DDB_SetReceiveVectorNA <- function(vec, NAIndex) {
2222
# which will be uploaded
2323
# (Used for dealing with NULLs in C++)
2424
DDB_SetUploadVectorNA <- function(vec) {
25-
NAIndex <- vector(mode = "integer", length = 0)
26-
for (j in 1:length(vec)) {
27-
if (is.na(vec[j]) == TRUE) {
28-
NAIndex <- c(NAIndex, j-1)
29-
}
30-
}
31-
return (NAIndex)
25+
return (which(is.na(vec)))
3226
}
3327

3428
# @Function
@@ -138,20 +132,20 @@ DDB_GetEntity <- function(xxdb_type) {
138132
if (ReturnScalarNA()) {
139133
result <- NA
140134
} else {
141-
result <- ReturnScalarString()
135+
result <- ReturnScalarDate()
142136
}
143137
Clear()
144-
return (as.Date(result))
138+
return (result)
145139

146140
} else if (xxdb_type == 15) {
147141
# Scalar DateTime
148142
if (ReturnScalarNA()) {
149143
result <- NA
150144
} else {
151-
result <- ReturnScalarString()
145+
result <- ReturnScalarTime()
152146
}
153147
Clear()
154-
return (as.POSIXct(result))
148+
return (result)
155149

156150
} else if (xxdb_type == 5) {
157151
# Logical Vector
@@ -182,17 +176,17 @@ DDB_GetEntity <- function(xxdb_type) {
182176

183177
} else if (xxdb_type == 16) {
184178
# Vector Date
185-
result <- ReturnVectorString()
179+
result <- ReturnVectorDate()
186180
result <- DDB_SetReceiveVectorNA(result, ReturnVectorNAIndex())
187181
Clear()
188-
return (as.Date(result))
182+
return (result)
189183

190184
} else if (xxdb_type == 17) {
191185
# Vector DateTime
192-
result <- ReturnVectorString()
186+
result <- ReturnVectorTime()
193187
result <- DDB_SetReceiveVectorNA(result, ReturnVectorNAIndex())
194188
Clear()
195-
return(as.POSIXct(result))
189+
return(result)
196190

197191
} else if (xxdb_type == 9) {
198192
# Logical Matrix
@@ -272,20 +266,21 @@ DDB_GetEntity <- function(xxdb_type) {
272266
result <- cbind(result, clm)
273267

274268
} else if (typelist[i] == 16) {
275-
clm <- ReturnTableColumnString(i)
269+
clm <- ReturnTableColumnDate(i)
276270
NAIndex <- ReturnTableColumnNAIndex(i)
277271
for (j in NAIndex) {
278272
clm[j] <- NA
279-
}
280-
result <- cbind(result, as.Date(clm))
273+
}
274+
result <- cbind(result, clm)
281275

282276
} else if (typelist[i] == 17) {
283-
clm <- ReturnTableColumnString(i)
277+
# date time
278+
clm <- ReturnTableColumnTime(i)
284279
NAIndex <- ReturnTableColumnNAIndex(i)
285280
for (j in NAIndex) {
286281
clm[j] <- NA
287282
}
288-
result <- cbind(result, as.POSIXct(clm))
283+
result <- cbind(result, clm)
289284

290285
} else {
291286
print("error in DataFrame")
@@ -346,7 +341,7 @@ DDB_GetEntity <- function(xxdb_type) {
346341
if (ReturnScalarNA(i)) {
347342
result <- NA
348343
} else {
349-
result <- ReturnScalarString(i)
344+
result <- ReturnScalarDate(i)
350345
}
351346
result <- as.Date(result)
352347

@@ -355,7 +350,7 @@ DDB_GetEntity <- function(xxdb_type) {
355350
if (ReturnScalarNA(i)) {
356351
result <- NA
357352
} else {
358-
result <- ReturnScalarString(i)
353+
result <- ReturnScalarTime(i)
359354
}
360355
result <- as.POSIXct(result)
361356

@@ -380,15 +375,15 @@ DDB_GetEntity <- function(xxdb_type) {
380375

381376
} else if (anytypelist[i] == 16) {
382377
# Vector Date
383-
result <- ReturnVectorString(i)
378+
result <- ReturnVectorDate(i)
384379
result <- DDB_SetReceiveVectorNA(result, ReturnVectorNAIndex(i))
385-
result <- as.Date(result)
380+
result <- result
386381

387382
} else if (anytypelist[i] == 17) {
388383
# Vector DateTime
389-
result <- ReturnVectorString(i)
384+
result <- ReturnVectorTime(i)
390385
result <- DDB_SetReceiveVectorNA(result, ReturnVectorNAIndex(i))
391-
result <- as.POSIXct(result)
386+
result <- result
392387

393388
} else if (anytypelist[i] == 9) {
394389
# Logical Matrix
@@ -458,20 +453,20 @@ DDB_GetEntity <- function(xxdb_type) {
458453
result <- cbind(result, clm)
459454

460455
} else if (typelist[k] == 16) {
461-
clm <- ReturnTableColumnString(k, i)
456+
clm <- ReturnTableColumnDate(k, i)
462457
NAIndex <- ReturnTableColumnNAIndex(k, i)
463458
for (j in NAIndex) {
464459
clm[j] <- NA
465460
}
466-
result <- cbind(result, as.Date(clm))
461+
result <- cbind(result, clm)
467462

468463
} else if (typelist[k] == 17) {
469-
clm <- ReturnTableColumnString(k, i)
464+
clm <- ReturnTableColumnTime(k, i)
470465
NAIndex <- ReturnTableColumnNAIndex(k, i)
471466
for (j in NAIndex) {
472467
clm[j] <- NA
473468
}
474-
result <- cbind(result, as.POSIXct(clm))
469+
result <- cbind(result, clm)
475470

476471
} else {
477472
print("error in DataFrame")
@@ -539,12 +534,12 @@ DDB_UploadScalarDate <- function(date) {
539534
# Parse a date type vector to C++ string vector to upload,
540535
# at the same time, deal with NA in vector
541536
DDB_UploadVectorDate <- function(vec) {
542-
date_str_vec <- vector(mode = "character", length = 0)
543-
for (i in 1:length(vec)) {
544-
date_str_vec <- c(date_str_vec, as.character(vec[i]))
545-
}
537+
#date_str_vec <- vector(mode = "character", length = 0)
538+
#for (i in 1:length(vec)) {
539+
# date_str_vec <- c(date_str_vec, as.character(vec[i]))
540+
#}
546541
NAIndex <- DDB_SetUploadVectorNA(vec)
547-
UploadVectorDate(date_str_vec, NAIndex)
542+
UploadVectorDate(vec, NAIndex)
548543
}
549544

550545
# @Function
@@ -557,12 +552,12 @@ DDB_UploadScalarDateTime <- function(datetime) {
557552
# Parse a datetime type vector to C++ string vector to upload
558553
# at the same time, deal with NA in vector
559554
DDB_UploadVectorDateTime <- function(vec) {
560-
date_time_str_vec <- vector(mode = "character", length = 0)
561-
for (i in 1:length(vec)) {
562-
date_time_str_vec <- c(date_time_str_vec, as.character(vec[i]))
563-
}
555+
#date_time_str_vec <- vector(mode = "character", length = 0)
556+
#for (i in 1:length(vec)) {
557+
# date_time_str_vec <- c(date_time_str_vec, as.character(vec[i]))
558+
#}
564559
NAIndex <- DDB_SetUploadVectorNA(vec)
565-
UploadVectorDateTime(date_time_str_vec, NAIndex)
560+
UploadVectorDateTime(vec, NAIndex)
566561
}
567562

568563
# @Function
@@ -589,13 +584,25 @@ DDB_UploadVector <- function(vec) {
589584
NAIndex <- DDB_SetUploadVectorNA(vec)
590585
UploadVectorDouble(vec, NAIndex)
591586

592-
} else if (is.character(vec)) {
587+
} else if (is.character(vec) || class(vec) == "factor") {
593588

594589
NAIndex <- DDB_SetUploadVectorNA(vec)
595590
UploadVectorString(vec, NAIndex)
596591

597-
} else {
592+
} else if (length(class(vec)) > 1 &&
593+
class(vec)[1] == "POSIXct") {
594+
595+
NAIndex <- DDB_SetUploadVectorNA(vec)
596+
UploadVectorDateTime(vec, NAIndex)
597+
598+
} else if (class(vec) == "Date") {
599+
NAIndex <- DDB_SetUploadVectorNA(vec)
600+
UploadVectorDate(vec, NAIndex)
601+
602+
}
603+
else {
598604
print("[ERROR] Vector type not support yet.")
605+
print("If you try to upload a dataframe, please add stringsAsFactors=FALSE")
599606
return (NULL)
600607
}
601608

@@ -719,14 +726,10 @@ DDB_UploadEntity <- function(args) {
719726
DDB_UploadVector(args[[i]])
720727
} else if (is.vector(args[[i]]) && length(args[[i]]) == 1) {
721728
DDB_UploadScalar(args[[i]])
722-
} else if (class(args[[i]]) == "Date" && length(args[[i]]) == 1) {
723-
DDB_UploadScalarDate(args[[i]])
724-
} else if (class(args[[i]]) == "Date" && length(args[[i]]) > 1) {
725-
DDB_UploadVectorDate(args[[i]])
726-
} else if (class(args[[i]]) == c("POSIXct", "POSIXt") && length(args[[i]]) == 1) {
727-
DDB_UploadScalarDateTime(args[[i]])
728-
} else if (class(args[[i]]) == c("POSIXct", "POSIXt") && length(args[[i]]) > 1) {
729+
} else if (length(class(args[[i]])) == 2 && class(args[[i]])[1] == "POSIXct") {
729730
DDB_UploadVectorDateTime(args[[i]])
731+
} else if (class(args[[i]]) == "Date") {
732+
DDB_UploadVectorDate(args[[i]])
730733
} else {
731734
print("Data form not support yet")
732735
Clear()

R/RcppExports.R

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,14 @@ ReturnScalarString <- function(index = -1L) {
141141
.Call('_RDolphinDB_ReturnScalarString', PACKAGE = 'RDolphinDB', index)
142142
}
143143

144+
ReturnScalarTime <- function(index = -1L) {
145+
.Call('_RDolphinDB_ReturnScalarTime', PACKAGE = 'RDolphinDB', index)
146+
}
147+
148+
ReturnScalarDate <- function(index = -1L) {
149+
.Call('_RDolphinDB_ReturnScalarDate', PACKAGE = 'RDolphinDB', index)
150+
}
151+
144152
ReturnVectorBool <- function(index = -1L) {
145153
.Call('_RDolphinDB_ReturnVectorBool', PACKAGE = 'RDolphinDB', index)
146154
}
@@ -157,6 +165,14 @@ ReturnVectorString <- function(index = -1L) {
157165
.Call('_RDolphinDB_ReturnVectorString', PACKAGE = 'RDolphinDB', index)
158166
}
159167

168+
ReturnVectorDate <- function(index = -1L) {
169+
.Call('_RDolphinDB_ReturnVectorDate', PACKAGE = 'RDolphinDB', index)
170+
}
171+
172+
ReturnVectorTime <- function(index = -1L) {
173+
.Call('_RDolphinDB_ReturnVectorTime', PACKAGE = 'RDolphinDB', index)
174+
}
175+
160176
ReturnVectorNAIndex <- function(index = -1L) {
161177
.Call('_RDolphinDB_ReturnVectorNAIndex', PACKAGE = 'RDolphinDB', index)
162178
}
@@ -233,6 +249,14 @@ ReturnTableColumnDouble <- function(index, entity_index = -1L) {
233249
.Call('_RDolphinDB_ReturnTableColumnDouble', PACKAGE = 'RDolphinDB', index, entity_index)
234250
}
235251

252+
ReturnTableColumnTime <- function(index, entity_index = -1L) {
253+
.Call('_RDolphinDB_ReturnTableColumnTime', PACKAGE = 'RDolphinDB', index, entity_index)
254+
}
255+
256+
ReturnTableColumnDate <- function(index, entity_index = -1L) {
257+
.Call('_RDolphinDB_ReturnTableColumnDate', PACKAGE = 'RDolphinDB', index, entity_index)
258+
}
259+
236260
ReturnTableColumnString <- function(index, entity_index = -1L) {
237261
.Call('_RDolphinDB_ReturnTableColumnString', PACKAGE = 'RDolphinDB', index, entity_index)
238262
}

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ on _DolphinDB_ server, while receiving object from server in the form and type o
2323

2424
---
2525

26-
### 2. How to use
26+
### 2. Install
2727

2828
#### 2.1 Install _R_ Environment
2929

3030
* For __Linux__ user
3131
* `sudo apt-get install r-base`
3232
* __OR__ download and install manually : https://www.r-project.org/
33+
* For __Windows__ user
34+
* Download and install the r base packages and the rtools at https://www.r-project.org/
3335

3436
#### 2.2 Get into _R_ CMD
3537

@@ -46,6 +48,14 @@ on _DolphinDB_ server, while receiving object from server in the form and type o
4648

4749
* In _R_ CMD, type `devtools::install_github("dolphindb/api-r")`.
4850
* This command will automatically download and install _RDolphinDB_ and its dependency package.
51+
* For __Windows__ user
52+
* If the Installation failed with message: *Warning in system(cmd) : 'make' not found*. Just try:
53+
54+
```R
55+
Sys.setenv(PATH = paste("*InstallDirectory*/Rtools/bin", Sys.getenv("PATH"), sep=";"))
56+
Sys.setenv(BINPREF = "*InstallDirectory*/Rtools/mingw_64/bin")
57+
```
58+
4959
* After installation, the package will be compiled and linked by _g++_ automatically.
5060

5161
#### 2.5 Use the _RDolphinDB_ Package
@@ -66,8 +76,8 @@ if (conn@connected) {
6676
dbClose(conn)
6777
```
6878

69-
---
7079

80+
---
7181
### 3. Documentation
7282

7383
#### 3.1 In _R_ CMD
16 Bytes
Binary file not shown.

src/Makevars.win

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
PKG_CXXFLAGS = -std=c++11 -D WINDOWS
1+
PKG_CXXFLAGS = -std=c++11 -D WINDOWS
2+
PKG_LIBS = $(LDFLAGS) -lwsock32 -lws2_32

0 commit comments

Comments
 (0)