Split .txt flile in lines/rows

I have a .txt file with different lines, like this:

PokerStars Hand #218755078355: Hold'em No Limit ($0.01/$0.02 USD) - 2020/09/24 13:18:49 ET
Table 'Spitzer III' 6-max Seat #1 is the button
Seat 1: MSC1266 ($1.90 in chips)
Seat 2: Cereghetti16 ($2.03 in chips)
Seat 3: Trytopredict ($2 in chips)
Seat 4: klariti ($2.60 in chips)
Seat 5: P.H.F.17 ($1.52 in chips)
Seat 6: FerzRu ($3.99 in chips)

I used readtext library to read it, but it compresses the whole file into a cell.

There is any way to create a dataframe where each line is a row?

Do you use HEM / PT4 etc?
If so, do you know you can connect directly to your database via R, then you can filter and extract just about any collection of data you can imagine.

I haven't played in years, but if I dig about the depths of this machine I might have some old scripts lying around

You can use readLines to read a text file in as a vector of strings.

No, I did not know about that i could connect R to my database! I have Holdem Manager 2.
I will google that, but If you have any hint or script to share, i would really appreciate it.

Thank you!!

Thanik you! That totally solves it!

1 Like

Firstly, readLines is a perfectly cromulent way to read your HH line by line, but it will need some extra processing to be useful, while you can get them from your database ready to use, along with as every stat from every hand ever.

I couldn’t find any old scripts, but I do still have my database, so I had a quick look to see what I could remember… which is not much.

I used PT4, which uses PosgreSQL, I don’t know which db HEM2 uses, but connecting to the database will likely be different for you.

There are several packages available for working with databases, but here are the ones I used for this.


To connect to my database:

con <- dbConnect(
  drv = 'PostgreSQL',
  dbname = 'PT4 DB',
  user = '*****',
  password = '*****')

table_list <- dbListTables(con)

I have 38 tables I can extract.


#  [1] "cash_hand_summary"               
#  [2] "cash_hand_player_statistics"     
#  [3] "cash_hand_player_combinations"   
#  [4] "cash_hand_histories"             
#  [5] "cash_limit"                      
#  [6] "cash_table"                      
#  [7] "cash_table_session_summary"      
#  [8] "tourney_hand_summary"            
#  [9] "tourney_hand_player_combinations"
# [10] "tourney_hand_player_statistics"  
# [11] "tourney_blinds"                  
# [12] "tourney_summary"                 
# [13] "tourney_results"                 
# [14] "tourney_table"                   
# [15] "tourney_hand_histories"          
# [16] "tourney_table_type"              
# [17] "lookup_tourney_type"             
# [18] "lookup_hand_groups"              
# [19] "lookup_hand_ranks"               
# [20] "lookup_hole_cards"               
# [21] "lookup_suits_omaha"              
# [22] "lookup_positions"                
# [23] "lookup_sites"                    
# [24] "lookup_actions"                  
# [25] "lookup_tags"                     
# [26] "tags"                            
# [27] "notes"                           
# [28] "notes_auto"                      
# [29] "player"                          
# [30] "settings"                        
# [31] "cash_cache"                      
# [32] "cash_custom_cache"               
# [33] "tourney_cache"                   
# [34] "tourney_custom_cache"            
# [35] "live_tourney_player"             
# [36] "live_cash_table"                 
# [37] "live_cash_player"                
# [38] "live_tourney_table"

You can select and join these in any way you like using the dbplyr package.

WARNING: Be ready for some serious mind melting overload :dizzy_face::exploding_head:

Some of these are simple lookup tables others, depending on how many hands you have played, are tables of millions of rows x hundreds of columns!

To get individual tables you would do something like:

all_player_stats <- tbl(con, 'cash_hand_player_statistics')

Remember to disconnect from your database


Its pretty cool what you can do - I remember having a script that could read the HH and update HUD stats in (slightly lagged) real time, when my HUD wasn't working.

Unfortunately, that's all I've got right now. If you go down this route, I'd be interested to hear how you get on

Thank you so much for this information! I will try to do some Machine Learning to label different types of players. I will let you know my results as soon as i have them!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.