[R-SIG-Finance] from tibble to journal

Enrico Schumann e@ @end|ng |rom enr|co@chum@nn@net
Fri Mar 7 16:55:50 CET 2025


On Fri, 07 Mar 2025, Arnaud Gaboury writes:

> I have one tibble 'journal_tb' with this structure:
>
> gabx using magnolia [R] str(journal_tb)
> tibble [72 × 4] (S3: tbl_df/tbl/data.frame)
>  $ timestamp : POSIXct[1:72], format: "2024-12-16 18:00:00" "2024-12-16
> 18:00:00" "2024-12-16 18:00:00" "2024-12-16 18:00:00" ...
>  $ instrument: chr [1:72] "FTMUSDT" "SUIUSDT" "ETHUSDT" "ENAUSDT" ...
>  $ amount    : num [1:72] 284270 80024 91.9 207836 9.34 ...
>  $ price     : num [1:72] 1.38 4.73 4038 1.19 107012 ...
>
> When transforming to a PMwR journal:
>
> gabx using magnolia [R] my_journal <- as.journal(my_journal_tb)
>
> I have this error: Error in names[[i]] : subscript out of bounds
>
> I have double checked my columns but everything looks fine.
>
> How can I solve this out of bounds error?
>
> Thnak you for help

Hm, the 'str' output is for 'journal_tb', but below you
try to coerce 'my_journal_tb'. Is this simply a typo?

In any case, we would need a small reproducible example to
see why it does not work, e. g. by using
dput(my_journal_tb).    [Ideally only a few rows.]

I can do this, for instance, without problems:

    library("PMwR")
    d <- data.frame(timestamp = c("2024-12-16 18:00:00",
                                  "2024-12-16 18:00:00"),
                    instrument= c( "FTMUSDT", "SUIUSDT"),
                    amount  = c(284270, 80024),
                    price  = c(1.38, 4.73))
    as.journal(d)
    ## 1     FTMUSDT  2024-12-16 18:00:00  284270   1.38
    ## 2     SUIUSDT  2024-12-16 18:00:00   80024   4.73
    ## 
    ## 2 transactions  
    
    library("tibble")
    d <- as_tibble(d)
    as.journal(d)
    ## 1     FTMUSDT  2024-12-16 18:00:00  284270   1.38
    ## 2     SUIUSDT  2024-12-16 18:00:00   80024   4.73
    ## 
    ## 2 transactions  



-- 
Enrico Schumann
Lucerne, Switzerland
https://enricoschumann.net



More information about the R-SIG-Finance mailing list