Skip to content

Commit

Permalink
Update the "Usage" example in the README (#36)
Browse files Browse the repository at this point in the history
* update readme usage example

* change part of example
  • Loading branch information
joshday authored Jun 20, 2024
1 parent e5d4c37 commit 489b320
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,31 @@ Read xBase / dBASE III+ [.dbf](https://en.wikipedia.org/wiki/.dbf) files in Juli
## Usage

```julia
using DBFTables
dbf = DBFTables.Table("test.dbf")

# whole columns can be retrieved by their name
# note that this creates a copy, so instead of repeated `dbf.field` calls,
# it is faster to once do `field = dbf.field` and then use `field` instead
dbf.INTEGER # => Union{Missing, Int64}[100, 101, 102, 0, 2222222222, 4444444444, missing]

# example function that iterates over the rows and uses two columns
function sumif(dbf)
total = 0.0
for row in dbf
if row.BOOLEAN && !ismissing(row.NUMERIC)
value += row.NUMERIC
end
end
return total
using DBFTables, DataFrames

df = DataFrame(
x = 1:5,
y = rand(Bool, 5),
z = ["a", "b", "c", "d", "e"]
)

# Write any Tables.jl source to a .dbf file
path = tempname()
DBFTables.write(path, df)

# Read the data back in from the .dbf file
dbf = DBFTables.Table(path)

# Retrieve columns by their name
dbf.x

# Iterate over the rows (values can be accessed by column name)
for row in dbf
@info (row.x, row.y, row.z)
end

# for other functionality, convert to other Tables such as DataFrame
using DataFrames
df = DataFrame(dbf)
# Pass the DBFTables.Table to any Tables.jl sink
df2 = DataFrame(dbf)
```

## Format description resources
Expand Down

2 comments on commit 489b320

@joshday
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/109441

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.2.6 -m "<description of version>" 489b320ea8794eee57b7111db335d34e383e2019
git push origin v1.2.6

Please sign in to comment.