gtrendsR- make.names中的错误(col.names,unique = TRUE):无效的多字节字符串1

时间:2018-04-18 04:24:54

标签: r gtrendsr

我正在尝试使用gtrendsR包运行一个简单的命令,但是它给出了一个错误,说明 make.names中的错误(col.names,unique = TRUE):   无效的多字节字符串1

以下是代码:

batch_size = 5
# Load data
x = tf.placeholder (tf.float32, [None, 416, 416, 3], name="x")
y = tf.placeholder (tf.float32, [None, 416, 416, 1], name="y")

# Contrast normalization and computation
x_gcn = tf.map_fn (lambda img : tf.image.per_image_standardization (img), x)
logits = create_network_5C (x_gcn)

# Having label at the same dimension as the output
y_p = tf.nn.avg_pool (tf.sign (y),
                      ksize=[1,16,16,1], strides=[1,16,16,1], padding="SAME")
y_rshp = tf.reshape (y_p, [batch_size, 416//16, 416//16])
y_bin = tf.cast (y_rshp > .5, tf.int32)
y_1hot = tf.one_hot (y_bin, 2)

# Compute error
error = loss (logits, y_1hot, 2)
optimizer = tf.train.AdamOptimizer (learning_rate=args.eta).minimize (error)

# Run the session
init_op = tf.global_variables_initializer ()
with tf.Session () as session :
    session.run (init_op)
    err, _ = session.run ([error, optimizer],
                           feed_dict={ x: image_batch,
                                       y: label_batch })

2 个答案:

答案 0 :(得分:0)

Sys.setlocale("LC_CTYPE", "Chinese (Traditional)")

如果错误是由于不同的语言设置,那么它应该适合您。

但是,如果您想搜索其他语言的关键字而不是英语(例如我的中文),那么另一个问题是检索到的数据中的关键字可能会被编码。我的诀窍就是将LC_CTYPE重置为原始设置。

class Membership < ApplicationRecord
  belongs_to :user
  belongs_to :event
  enum type: [ :host, :reservation, :attendance ]
end

class Event < ApplicationRecord
  belongs_to :poster, class_name: "User"

  has_many :host_memberships, -> { host }, class_name: "Membership"
  has_many :reservation_memberships, -> { reservation }, class_name: "Membership"
  has_many :attendance_memberships, -> { attendance }, class_name: "Membership"

  has_many :hosts, through: :host_memberships, source: "User"
  has_many :reservations, through: :reservation_memberships, source: "User"
  has_many :attendees, through: :attendance_memberships, source: "User"
end

class User < ApplicationRecord
  has_many :posts, class_name: "Event"

  has_many :host_memberships, -> { host }, class_name: "Membership"
  has_many :reservation_memberships, -> { reservation }, class_name: "Membership"
  has_many :attendance_memberships, -> { attendance }, class_name: "Membership"

  has_many :hosted, through: :host_memberships, source: "Event"
  has_many :reservations, through: :reservation_memberships, source: "Event"
  has_many :attended, through: :attendance_memberships, source: "Event"
end

答案 1 :(得分:0)

针对像我这样有困难的人。

即使某些关键字效果很好,但某些关键字却效果不佳。我不知道

有什么不同。

出现了一些[Error in make.names(col.names, unique = TRUE) : invalid multibyte string]探针。

我尝试了很多事情,但没有任何效果

我尝试过但没有起作用的事情

  1. read.csv(~, fileEncoding = "UTF-8") and (~~ encoding = "UTF-8")
  2. 记事本中的
  3. re-save文件
  4. Encoding()

解决方案

首先,我使用“韩语”并使用Windows10,我所有的CSV文件都被编码为(ASCII)

如果我重新编码原始CSV文件,则在读取文件步骤中会出现问题。

结论

在上述情况下,Sys.setlocale()是我的唯一选择,但有一些限制。

您可以找到自己的Sys.locale by Sys.getlocale()`。

就我而言,

["LC_COLLATE=Korean_Korea.949;LC_CTYPE=Korean_Korea.949;LC_MONETARY=Korean_Korea.949;LC_NUMERIC=C;LC_TIME=Korean_Korea.949"]

所以我将语言环境设置更改为Sys.setlocale("LC_CTYPE", "English")

限制

即使“ geo”是正确的,由于对related_topics的翻译,“ related_topics”的结果也令人怀疑。

下面是我的代码

google.trends = gtrends(keyword = key_final, geo = "KR", gprop = "web", time = "2018-01-01 2018-11-30")[[1]]
google.trends = dcast(google.trends, date ~ keyword + geo, value.var = "hits")
rownames(google.trends) = google.trends$date
google.trends$date = NULL
google.trends
plot(google.trends[[1]], type = 'l')

Screenshot 1

但结果已翻译

Screenshot 2