It's not possible. Once a transaction is broadcasted to the network you can't call it back.
What you can do is send another transaction with a higher gas price that being included in a block before the original transaction will make the original transaction invalid thus it will never be executed and included in a block.
- Let's say you sent a transaction A that from your estimations would require 500k gas.
- After some time this transaction is not included in a block but you know that it will fail and only waste 500k gas.
- You send a transaction B that simply transfers all your ether from your account to another account. This would cost you only 21k gas (the intrinsic transaction cost). Since now the original transaction is invalid because there is no balance on the sender's account it will be discarded by all nodes. It cost you 21k gas which depending on the gas price may be cheaper than the gas cost of the original transaction.
In fact if you can send any other transaction from the same account and it will be included in a block before the original transaction (one way is to set the gas price higher than in the original transaction) it will make the original transaction invalid as the transaction nonce validation will fail (every transaction must contain nonce which must be equal to the account nonce which in turn is incremented with every new transaction). Transaction validation rules are specified in the yellow paper section 6.