r logic