Can I ask R what the unexpected symbol is?

My code apparently has an unexpected symbol; I get this a lot. Is there a way I can ask R what's wrong instead of manually trying to catch what this symbol is?

For reference this was my code:

data_glom$Function <- factor(data_glom$Function,levels = c("Saprotroph","Pathotroph", "Symbiotroph", "Pathotroph_Saprotroph", "Pathotroph_Saprotroph_Symbiotroph", "Pathotroph_Symbiotroph", "Saprotroph_Symbiotroph"))

Did you check that the levels are all spelled correctly and match the values in data_glom$Function? Or do you think it's an encoding problem?

unique(data_glom$Function)
setdiff(data_glom$Function, c("Saprotroph","Pathotroph", "Symbiotroph", "Pathotroph_Saprotroph", "Pathotroph_Saprotroph_Symbiotroph", "Pathotroph_Symbiotroph", "Saprotroph_Symbiotroph"))

Or do you think it's an encoding problem? If the file has come to/from Unix to/from Windows you might need to change the encoding. I know you can do this in Notepad++.

[See this post, for example.](https://superuser.com/questions/294219/what-are-the-differences-between-linux-and-windows-txt-files-unicode-encoding#:~:text=Most%20modern%20(i.e.%2C%20since%202004,in%20a%20legacy%20code%20page.)

" Windows, however, lacks native support for UTF-8. It internally works in UTF-16, and assumes that char -based strings are in a legacy code page. Fortunately, Notepad is capable of reading UTF-8 files; unfortunately, "ANSI" encoding is still the default."

No, I use Mac. Everything is spelled correctly and I've tried using both dashes and underscores to see if that was the issue (ie. although Pathotroph-Saprotroph is spelled that way in the table I've also tried Pathotroph_Saprotroph)

Hi!

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:


Short Version

You can share your data in a forum friendly way by passing the data to share to the dput() function.
If your data is too large you can use standard methods to reduce it before sending to dput().
When you come to share the dput() text that represents your data, please be sure to format your post with triple backticks on the line before your code begins to format it appropriately.

```
( example_df <- structure(list(Sepal.Length = c(5.1, 4.9, 4.7, 4.6, 5, 5.4, 4.6, 
5, 4.4, 4.9), Sepal.Width = c(3.5, 3, 3.2, 3.1, 3.6, 3.9, 3.4, 
3.4, 2.9, 3.1), Petal.Length = c(1.4, 1.4, 1.3, 1.5, 1.4, 1.7, 
1.4, 1.5, 1.4, 1.5), Petal.Width = c(0.2, 0.2, 0.2, 0.2, 0.2, 
0.4, 0.3, 0.2, 0.2, 0.1), Species = structure(c(1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L), .Label = c("setosa", "versicolor", "virginica"
), class = "factor")), row.names = c(NA, -10L), class = c("tbl_df", 
"tbl", "data.frame")))
```

Hi @hank00000,
Has any of your code been cut-and-pasted from other software (e.g. Word)? In which case you may have some so-called "smart quote" characters (non-ASCII) that R cannot handle.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.