C W
2021-Jan-26 19:29 UTC
[R] Is there anyone who uses both R and Python here? How do you debug? Perhaps in RStudio?
Hello all, I'm a long time R user, but recently also using Python. I noticed that RStudio rolled out Python through reticulate. It's great so far! My question is, how do you debug in Python? In R, I simply step through the code script in my console with cmd+enter. But you can't do that with Python, some of them are objects. Here's my example. class person: def __init__(self, id, created_at, name, attend_date, distance): """Create a new `person`. """ self._id = id self.created_at = created_at self.name = name self.attend_date = attend_date self.distance = distance @classmethod def get_person(self, employee): """Find and return a person by. """ return person(employee['created_at'], employee['id'], employee['name'], employee['attend_date'], employee['distance'] ) The error message says self._id was 'str', but expecting an 'int'. I can't do:> self._id = 5I guess it's "hidden". Can't really assign and test like that. It seems hardcore Python programmers just use a debugger, and do not understand the greatness of interactive IDE and console. I'd still like to stay in IDE, hopefully. So, how are the R users coping with object classes? Do you just instantiate every time? What if you got 10 of these class person objects to debug? I know this may be a Python question. But, I really wanted to see from a R user's working experience. Thanks a lot, Mike [[alternative HTML version deleted]]
Robert Knight
2021-Jan-27 16:31 UTC
[R] Is there anyone who uses both R and Python here? How do you debug? Perhaps in RStudio?
An iterative process works well. Python to get the data desired and then Rscript script.r from a command line. My process involves building a script in R using, using Rstudio, Pycharm, VS Code, Kate, or some other editor. Then using data input built with Python as input to Rscript. The R scripts produce excel files or CSV data for other use RStudio is amazing for some slow pace academic work. The "expected a numeric but got a char" error appeared to often for my needs and so the workflows wound up with Python building data that's already cleaned for use in R to avoid data import troubles. My code use a functional paradigm rather than object oriented paradigm. Python does more than just munge my data since it handled many mathematic operations on it, but it's ultimate purpose is to clean large amounts of data to avoid import errors in R. On Wed, Jan 27, 2021, 1:49 AM C W <tmrsg11 at gmail.com> wrote:> Hello all, > > I'm a long time R user, but recently also using Python. I noticed that > RStudio rolled out Python through reticulate. It's great so far! > > My question is, how do you debug in Python? > > In R, I simply step through the code script in my console with cmd+enter. > But you can't do that with Python, some of them are objects. > > Here's my example. > class person: > def __init__(self, id, created_at, name, attend_date, distance): > """Create a new `person`. > """ > self._id = id > self.created_at = created_at > self.name = name > self.attend_date = attend_date > self.distance = distance > > @classmethod > def get_person(self, employee): > """Find and return a person by. > """ > return person(employee['created_at'], > employee['id'], > employee['name'], > employee['attend_date'], > employee['distance'] > ) > > The error message says self._id was 'str', but expecting an 'int'. I can't > do: > > self._id = 5 > I guess it's "hidden". Can't really assign and test like that. > > It seems hardcore Python programmers just use a debugger, and do not > understand the greatness of interactive IDE and console. I'd still like to > stay in IDE, hopefully. > > So, how are the R users coping with object classes? Do you just instantiate > every time? What if you got 10 of these class person objects to debug? > > I know this may be a Python question. But, I really wanted to see from a R > user's working experience. > > Thanks a lot, > > Mike > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]