Troubleshooting and general tips

Go down

Troubleshooting and general tips

Post by Santiak on Fri Apr 01, 2016 10:58 pm

Heyho folks,

First and foremost, this first post is a general disclaimer: Silly me didn't know/realize/notice that Katrin and Riccardo had made a walkthrough for the report, so my own report is more or less homebrewed, for which reason I can't say with certainty that my 'methods' are correct; however, so long as they get the job done, I do think you can use them if need be.

Secondly, I'm also rather new to coding in R - my only previous experience is with Basic (or C++), which is a generalized coding language - more or less considered the "latin" of coding, in so far that if you know a bit of C++, you know a bit of everything (but of course that doesn't mean you can speak everything in the slightest). As such, there is very likely much more elegant and easy ways to go about getting the results than the suggestions I can offer, albeit that is more or less the nature of the beast that is coding.

Thirdly, I try to steer clear of having to install additional libraries, call me a hipster in those regards, but I'd rather learn the basics than rely too heavily on libraries, which is a very silly and stupid thing to do, because they can make your life much, much easier - a good example is renaming columns in a dataframe.
With a library called "plyr", it becomes as easy as:
plyr wrote:
rename(DataSet, c("column1"="newname1", "column2"="newname2")

Without, it's a bit messier:
you probably haven't heard of it wrote:
names(MeanAll) <- c("Newname1", "Newname2")
Which might seem less messy, but if you look closely at the code, you'll notice I'm assigning new values to the dataframe (<-), and that I have to name the columns in order, or use an alternate code to rename individual columns.

The "beauty" (No! Don't run! I know I said "Beauty" in regards to coding, but hear me out!) of coding, is that there's never just one way of doing things, and what you prefer - what 'style' - is up to you.

Bottom line is, don't take my suggestions - or anyones suggestions - as the only way to do something, it's likely that there is another way, and it's possible there's a way that seems more logical to you.

Now to some advice on troubleshooting.
Again, I'm only speaking from personal experience, and I may very well be blowing hot air up your proverbial backsides, and while that was a tried (yeahp) and trusted way of resuscitating drowning victims in ye olden days, it follows that I may be giving you very, very bad advise, and you'll still be sputtering on the beach.

Santiak
Admin

Posts : 23
Join date : 2016-02-24

View user profile

Back to top Go down

Re: Troubleshooting and general tips

Post by Santiak on Fri Apr 01, 2016 11:12 pm

(I'll of course add to this list as brain-farts roll in)

Troubleshooting:
- The code, it does nothing!
If a line of code refuses to cooperate, look carefully at the red text that follows it.
Sometimes your code will produce the desired result regardless, so you may become 'numb' to this red text, but other times it can give you good hints in regards to where to look for a potential mistake.

The culprit I've most often encountered, is a stray comma or parenthesis. R will think you're a lunatic, opening your mouth without saying anything.
Look over the code for any such stray symbols, and either speak your mind (add the missing command) or close your mouth (delete the stray symbol).

Other possibilities is that you may be trying to use variables that R either doesn't need or doesn't understand in that context; some graphs only take x-values, while others need both x- and y-values, add in or leave out one respectively, and R will get miffed at you.

- Well, that was unexpected:
Sometimes you might get a "+" instead of a ">", what this means is - to continue the already strained metaphor above - that R is waiting for you to finish a sentence.
It most often means you've forgotten to close a parenthesis somewhere, so count the total number of "(" vs. ")", and make sure they're even.
This most often occurs if you've deleted part of a code to try and clean it up, but can also be a stray 'helping hand' from R, as it will sometimes automatically enter parenthesis if it thinks it'll lighten your workload.

- I was sure it should have worked
If you write up a code that you're positive should have worked but doesn't, or isn't working as you had imagined, play a bit with it.
If you're feeling cautious, copy/paste the line from R into notepad, or use the script editor (top window) in R itself.
Then try to pick apart the code; let it be the proverbial fly and you the sadistic child pulling off its wings, see how it reacts if you switch x- and y-values, if you add an extra command, or remove one.

Note that sometimes R can be very picky, and if you - like me - tend to write the entire line in one go, e.g.:
Ain't noone got time fo dat wrote:
ggplot(DataFrame, aes(x=Blah, fill=Wut)) + geom_bar() + etc() + etc() + etc()
Then R might refuse to cooperate for some unbeknownst reason.

In these instances, try to revert to what we were taught during class; assign it all to a new variable:
Be gentle wrote:
I'mAVariable <- ggplot(Dataframe, aes(x=Blah, fill=Wut))
I'mAVariable <- I'mAVariable + geom_bar()
I'mAVariable <- I'mAVariable + etc()
I'mAVariable <- I'mAVariable + etc()
I'mAVariable
Note that the last line is to execute the variable (err.. that is, viewing it, not taking it out behind the barn and shooting it).

If both methods refuse to cooperate, delete some of the commands in the code, and see when it starts listening (i.e. pull of those wings).


Last edited by Santiak on Sat Apr 02, 2016 3:12 am; edited 1 time in total

Santiak
Admin

Posts : 23
Join date : 2016-02-24

View user profile

Back to top Go down

Re: Troubleshooting and general tips

Post by Santiak on Fri Apr 01, 2016 11:36 pm

Tips:
If you've ever played a puzzle game or adventure game (if not, I can highly recommend any of the old classics, "Monkey Island", "Day of the Tentacle", etc.), you know the joy of finally finding which non-sensical item to rub against another non-sensical item to produce what you needed; it can be infuriating, but once you find out you need to use the Rubber Chicken with a Pulley so you can traverse the rope extending over a crevasse, you'll feel ever so clever.
But I'm getting nostalgic; the point is that you should treat programming in R in much the same manner.

Don't think of R as a tool required to produce a product, but as toy to play with and explore.
As I mentioned above, there's no right or wrong way to do things in R, it is, to quote Larry David, a matter of "Whatever Works".

I know I probably sound like a code-monkey trying to pass off the steaming pile of questionable squishy stuff in his hands as a delicious banana, but would you believe I disliked coding as well?
I mentioned I tried my hand at Basic - the operative word there is "tried". I think I got to lesson 3 (making prompt/response programs) before I threw up my hands in despair and said "sod it".

All because I tried to learn Basic to accomplish something, to produce something, rather than to play with something.
When we started this class, I did very much the same with R.
But then I started playing with the values. Like seeing if perhaps there was a link between some of the variables that we weren't instructed to look into, like Empathy evaluation and Gender (don't look at me like that!)
I started trying to add fancy things like labels, or colours, or dividing the above according to Concept and Condition.

I wasn't working, I was exploring - I was failing miserably, and it was glorious. I was learning with every mistake - and best of all, R didn't blow up, nor did my data!
It got miffed now and again, I accidentally threw it into a loop ("A <- B <- A <- B"), but there was something fun (no, it really is a banana!) about seeing what concoctions I could come up with, as soon as I forgot about being right or correct, and instead started thinking about figuring out what I could do, or how I could do it.

Here's the corny bit:
I started having fun when I stopped thinking about the goal, and starting enjoying the journey, making pit-stops, going to that corny restaurant off the highway with the smelly toilets, taking a detour through that all but forgotten little town.

So my tip?
When you code, try not to think "How do I make a graph that shows exactly this", but instead "What can I find in all these values"; don't worry too much about a looming deadline. Start with investigating something you find interesting - start with "Punches to the face" as a product of "Mads graphing empathy as a function of Gender".

If you look into statistics that interest you out of a dataset, then:
You'll be eager to see the results.
You'll be motivated to figure out what about your code isn't working.
You'll eventaully find it and solve it.
And then comes the kicker; you can use that code to accomplish your goal, eventhough you never wrote it for the goal, but for your own silly brainfart. Smile

(I guess Jack was on to something, eh? .. points for getting the reference)

Santiak
Admin

Posts : 23
Join date : 2016-02-24

View user profile

Back to top Go down

Re: Troubleshooting and general tips

Post by Jav_otam on Sat Apr 02, 2016 2:49 pm

You, sir, code like a dairy farmer Smile

Jav_otam

Posts : 3
Join date : 2016-03-01

View user profile

Back to top Go down

Re: Troubleshooting and general tips

Post by Santiak on Sat Apr 02, 2016 11:29 pm

Jav_otam wrote:You, sir, code like a dairy farmer Smile
How appropriate, you code like a cow! Wink

Santiak
Admin

Posts : 23
Join date : 2016-02-24

View user profile

Back to top Go down

Re: Troubleshooting and general tips

Post by Santiak on Wed Apr 20, 2016 12:49 am

Google-fu:

As Riccardo and Katrin so kindly gave away during class, my only strength in terms of R is actually my familiarity with using Google for some very obscure searches (No, I said obscure, not obscene - things like finding the link between a kidnapping and the keyword "Cipher Manuscript", or what semi-obscure painter from the Barbizon school was doing in his final days)

The main thing to keep in mind, is that google can be both very picky, and very vague.
Sometimes you need to explicitly state what it is you want it to find, by adding quotation marks around your "keyword".
Other times, you need make it stop finding all those unrelated items by adding a hyphen before the -keyword
Or you can't quite figure out a fitting substitute for a certain word, or what the exact wording may be, so you add an * in place of that word.

For R related searches, I've found that it often helps heaps (say that 3 times fast) if you try to think of alternative terminologies.
To give a specific example, I was looking for ways to rename specific values in a column.
When "values" didn't get me anything useful, I tried "vectors"
When "vectors" didn't get me anything useful, I tried "results"
When "results" didn't get me anything useful, I tried "cells", and so on.

Other general tips is to never settle for just the first page of results, the answer you're looking for could easily be hidden around the proverbial corner.


The last piece of advice, is to get into the general terminology of R a bit, as people tend to write their tips in short-hand, and at first things can get quite confusing as you try to decipher it all, and if you're particularly unlucky, you might find someone who has seemingly written a short novel in place of a code, in which case try searching a bit - usually there's a neater code to be found somewhere, or consider the novel you found, as you might be able to make do with just a sentence from it, and not the entire thing.


Santiak
Admin

Posts : 23
Join date : 2016-02-24

View user profile

Back to top Go down

Re: Troubleshooting and general tips

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum