The behaviour of the fix_invalid subroutine in postcode_data_join() is a bit too haphazard to be run automatically in the middle of a user-facing function. It also makes the whole function harder to debug and read as a piece of code.
We should create a helper function that suggests replacements for invalid postcodes, and allow the user to replace these in their source data or as a step in their lookup process as they wish.
This makes it clear that any replacements are just suggestions, and it is up to the user to decide whether they are suitable.
It will also show more clearly to the user how many postcodes are invlaid, and which could be "fixed" and which could not.
The behaviour of the
fix_invalid
subroutine inpostcode_data_join()
is a bit too haphazard to be run automatically in the middle of a user-facing function. It also makes the whole function harder to debug and read as a piece of code.We should create a helper function that suggests replacements for invalid postcodes, and allow the user to replace these in their source data or as a step in their lookup process as they wish.
This makes it clear that any replacements are just suggestions, and it is up to the user to decide whether they are suitable.
It will also show more clearly to the user how many postcodes are invlaid, and which could be "fixed" and which could not.