added writeFromR