Imam sheds light on the matter through his famous work "an exposition on Forty Hadith" as following:
Why is it that you are eager to inform others about your pilgrimage by all possible means and about the number of times you undertook it?
Why are you not content with confining your charitable deeds to yourself alone, and what do you want to gain by informing the others of your acts of charity, for as soon as you find an opportunity you announce them?
If it is undertaken for the sake of God, and you intend that people should imitate you, and you think in terms of (the one who shows the path of virtue is as worthy as-the doer of it) while performing this deed, its display is justified; thank God, for He has enabled you to act with a clear conscience and pure heart.
But beware of the guiles of Satan while interrogating your self, for he can project the acts adulterated with riya’ as selfless and sacred.
If your action is not for the sake of God, then it is better to abstain from doing what you have been doing, for it amounts to sum’ah, i.e. advertisement of false virtues, which is a branch of the accursed tree of riya’; for God Almighty does not approve of it and condemns its perpetrator to Sijjin.
We ought to seek refuge in God from the vice of deceit, whose guiles are very subtle. We have a general idea that our deeds are not pure and sincere, because had we been His true servants, why does the Devil, despite promising not to impede the actions of His true servants, disturb our sanctity and make us an instrument of his evil designs?
For about forty years you imagine that you have been performing virtuous deeds in order to please God, whereas it occurs in a hadith that whosoever remains faithful to God for forty days, springs of wisdom emanate from his heart.
This is, therefore, a sign for us to comprehend that our deeds were not performed for the sake of God, though we ourselves are not conscious of it, and this is the main cause of our irremediable sickness.
Read more:
Imam Khomeini advised faithful people to rationally evaluate their deeds