Comments (2)
Hi @emilBeBri , this is an issue with data.table
and saving to disk, not qs
. You can see that even with other serialization methods, you get the same issue:
library(data.table)
dat1 <- data.table(id=c(1,1,1,2,2,2), runif(6,0,5), z = letters[1:6])
dat2 <- data.table(id=c(3,3,3,4,4,4), runif(6,0,5), z = letters[1:6])
saveRDS(dat1, file = "/tmp/dat1.rds")
dat1 <- readRDS("/tmp/dat1.rds")
saveRDS(dat2, file = "/tmp/dat2.rds")
dat2 <- readRDS("/tmp/dat2.rds")
for (DT in c('dat1', 'dat2')) {
get(DT)[, newcol := 1]
}
dat1
id V2 z
1: 1 2.2551426 a
2: 1 0.3937463 b
3: 1 1.4704248 c
4: 2 4.7696833 d
5: 2 3.8110676 e
6: 2 4.4503739 f
The reason is data.table
uses C reference pointers to places in memory:
> attributes(dat1)
...
$.internal.selfref
<pointer: 0x0>
A quick fix would be to re-wrap the data.table:
library(data.table)
library(qs)
dat1 <- data.table(id=c(1,1,1,2,2,2), runif(6,0,5))
dat2 <- data.table(id=c(3,3,3,4,4,4), runif(6,0,5))
qsave(dat1, './dat1.qs', preset='high')
dat1 <- data.table(qread('./dat1.qs'))
qsave(dat2, './dat2.qs', preset='high')
dat2 <- data.table(qread('./dat2.qs'))
for (DT in c('dat1', 'dat2')) {
get(DT)[, newcol := 1]
}
> dat1
id V2 newcol
1: 1 0.08454065 1
2: 1 4.36837604 1
3: 1 3.49920527 1
4: 2 0.02507492 1
5: 2 1.65069644 1
6: 2 1.29881559 1
Hopefully that answers your question. If it does, please feel free to close :)
from qs.
nice! Wrapping it in data.table is a neat trick to circumvent this. Just checked on the example data: You can also do it with setDT() and thereby not making any copiyng at all , so this is probably the most efficient solution (although perhaps more error-prone?)
from qs.
Related Issues (20)
- feature request: add meta data to qs file HOT 2
- Suggestion: caching pipe HOT 3
- FST works with dataframes HOT 6
- Binaries through r-universe HOT 1
- Reading specific chunks from disk HOT 1
- Reading QS file from website inside R session HOT 2
- To do: Add error message for file names too long
- Need to check for writeable path
- Feature Request: function to read attributes HOT 4
- feature request: report filename when giving warnings HOT 2
- Linking to libatomic required on 32-bit platforms HOT 4
- Error in qdeserialize(x) : Endian of system doesn't match file endian HOT 15
- Apple Silicon ? HOT 1
- Suggestion : default parameter nthread HOT 2
- can't install 'qs' package on remote server CentOS Linux 7 (Core) HOT 1
- replacement of save.image ? HOT 2
- zstd decompression error - qread() HOT 2
- Documentation and examples, especially for qsave_ptr HOT 1
- Unexpected behavior when loading .qs file HOT 2
- Extra memory usage when loading an object twice HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from qs.